<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%-- <s:head /> --%>
<script type="text/javascript" src="/gtimp/js/business/hgdata.js"></script>
<script type="text/javascript" src="/gtimp/js/hint/jquery.hint.js"></script>
<script type="text/javascript" src="/gtimp/js/rightClick/jquery.contextmenu.r2.js"></script>
<style>
    <!--
    .labelTD_80 {
        width: 80px;
        text-align: right;
        background-color: #e0ebf7;
        border-left: 1px solid #0070A3;
        font-size: 12px
    }

    .labelTD_40 {
        text-align: right;
        background-color: #e0ebf7;
        border-left: 1px solid #0070A3;
        font-size: 12px
    }

    -->
</style>
<script type="text/javascript">
    var checkDetail = $("#checkDetailInput").val();
    if (checkDetail == "T") {
        $(function () {
            $(":input").attr("readonly", "readonly");
            $("#queren1").hide();
            $("#queren2").hide();
        });
    } else {
        $("#pBtn").hide();
    }
    $(document).ready(function () {
        var supId = $("#declaration_sup").val();
        if (supId == null || supId == "undefined") {
            $("#declaration_sup_id").val("");
        }
    });
</script>
<div id="submit_declarate"></div>
<div id="tab_declarate">
    <div id="input_declare_goods" style="display: none;"></div>
    <div id="input_declare_suifudans" style="display: none;"></div>
    <input value="${declare.id }" type="hidden" name="declare.id"/>
    <input value="${checkDetail }" type="hidden" id="checkDetailInput"/>
    <ul class="ul1">
        <li class="li1" style="font-size: 14px; padding-top: 4px;">预录入编号:</li>
        <li class="li1"><input type="text" class="textInput" name="declare.sno"
                               maxlength="9" style="width: 150px;" value="${declare.sno}"></li>
        <li class="li1" style="font-size: 14px; padding-top: 4px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;报关报检业务代理人：</li>
        <li class="li1"><input style="width: 150px;" type="text" id="declaration_sup_id"
                               name="declare.supCompany.name" value="${declare.supCompany.name}"/><input
                type="hidden" id="declaration_sup" name="declare.supCompany.id"
                value="${declare.supCompany.id }"/></li>
        <li class="li1">
            <s:if test="{declare.id!=null}">
                &nbsp;&nbsp;<input type="button" style="width: 95px;" value="打印报关单" onclick="javascript:window.open('http://219.130.222.62:9480/WebReport/ReportServer?reportlet=qp/chukouhuowubaoguandan.cpt&ID=${declare.id}');" />
            </s:if>
        </li>
    </ul>
    <input type="hidden" class="textInput" name="declare.tex_company" value="${declare.tex_company}"
           disabled="disabled"/><!-- 纳税单位 -->
    <input type="hidden" name="declare.voyage_no" value="${declare.voyage_no}"><!-- 航次号 -->
    <input type="hidden" class="textInput" id="declaretion_type" name="declare.customs_type"
           value="${declare.customs_type}"/><!-- 报关单类型 -->
    <table rules="rows" id="baseInfoTB" class="baseInfoTB_bg">
        <tr>

            <td class="labelTD_80" id="label_ep">出口口岸</td>
            <td colspan="3"><input type="text" class="textInput" name="declare.export_port" style="width: 237px;"
                                   maxlength="20"
                                   value="${declare.export_port}" id="export_show" disabled="disabled">
                <input name="" value="${declare.export_port}"
                       id="export" type="hidden"/>
            </td>
            <td class="labelTD_80">备案号</td>
            <td><input type="text"
                       class="textInput validate[custom[recordCode]]" id="record_id"
                       name="declare.record_id" maxlength="12" onblur="checkRECORD_ID()"
                       value="${declare.record_id}"></td>
            <td class="labelTD_80" id="label_epdate">出口日期</td>
            <td><input type="text" class="textInput"
                       name="declare.export_date" value="${declare.export_date}"
                       disabled="disabled"></td>
            <td class="labelTD_80" id="label_epdate">申报日期</td>
            <td><input type="text" class="textInput" id="reportDate"
                       name="declare.report_date" disabled="disabled" value="${declare.report_date}"
            ></td>
        </tr>
        <tr>
            <td class="labelTD_80">经营单位</td>
            <td><input type="text" class="textInput" id="company_code" style="width:80px;"
                       name="declare.company_co" value="${declare.company_co}"
                       title="经营单位代码"></td>
            <td colspan="2">&nbsp;<input type="text" class="textInput"
                                         id="company_name" name="declare.company_name" style="width: 145px;"
                                         title="经营单位名称" value="${declare.company_name}"></td>
            <td class="labelTD_80">运输方式</td>
            <td><input type="text" class="textInput" id="transport_mode"
                       name="declare.transport_mode" value="${declare.transport_mode}"
                       disabled="disabled"></td>
            <td class="labelTD_80">运输工具名称</td>
            <td><input type="text" class="textInput"
                       name="declare.transport_na"
                       value="${declare.transport_na}"></td>
            <td class="labelTD_80">提运单号</td>
            <td><input type="text" class="textInput" name="declare.bl_no"
                       maxlength="15" title="最长15个字符" value="${declare.bl_no}"></td>
        </tr>
        <tr>
            <td class="labelTD_80" id="label_fahuo">发货单位</td>
            <td><input type="text" class="textInput" title="发货单位代码" style="width:80px;"
                       id="fahuo_company_co" name="declare.fahuo_company_co"
                       value="${declare.fahuo_company_co}"></td>
            <td colspan="2">&nbsp;<input type="text" class="textInput"
                                         id="fahuo_company_name" name="declare.fahuo_company_name"
                                         style="width: 145px;" title="发货单位名称"
                                         value="${declare.fahuo_company_name}"></td>
            <td class="labelTD_80">贸易方式</td>
            <td><input type="text" class="textInput" id="trade_show" value="${declare.trade_mode}"
                       name="declare.trade_mode"> <input
                    name="" id="trade" value="${declare.trade_mode}"
                    type="hidden"></td>
            <td class="labelTD_80">征免性质</td>
            <td><input type="text" name="declare.levymode" class="textInput" id="levy_show" value="${declare.levymode}">
                <input id="levy" type="hidden" name="" value="${declare.levymode}">
            </td>
            <td class="labelTD_80" id="label_lc_type">结汇方式</td>
            <td><input type="text" class="textInput" name="declare.lc_type"
                       id="lc_show" value="${declare.lc_type}"> <input
                    name="" id="lc" value="${declare.lc_type}"
                    type="hidden"></td>
        </tr>

        <!-- 		<tr style="display: none;"> -->
        <!-- 			<td class="labelTD_80">申报单位</td> -->
        <!-- 			<td><input type="text" class="textInput" -->
        <!-- 				name="declare.shenbao_company_co" title="申报单位代码" -->
        <%-- value="${declare.shenbao_company_co}"></td> --%>
        <!-- 			<td colspan="2"><input type="text" class="textInput" title="申报单位名称" -->
        <!-- 				name="declare.shenbao_company_name" style="width: 248px;" -->
        <%-- value="${declare.shenbao_company_name}"></td> --%>
        <!-- 			<td></td> -->
        <!-- 			<td></td> -->
        <!-- 		</tr> -->
        <tr>

            <td class="labelTD_80">许可证号</td>
            <td colspan="3"><input type="text" class="textInput" style="width:237px"
                                   name="declare.license_no" value="${declare.license_no}"></td>
            <td class="labelTD_80" id="label_arrived_country">运抵国</td>
            <td><input type="text" class="textInput" style="width:120px"
                       id="arrived_country_show" name="declare.arrived_country"
                       value="${declare.arrived_country}"> <input
                    name="" id="arrived_country"
                    value="${declare.arrived_country}" type="hidden">
            </td>
            <td class="labelTD_80" id="label_arrived_port">指运港</td>
            <td><input type="text" class="textInput" title=""
                       id="arrived_port_show" name="declare.arrived_port"
                       value="${declare.arrived_port}"> <input
                    name="" id="arrived_port"
                    value="${declare.arrived_port}" type="hidden"></td>
            <td class="labelTD_80" id="goods_place">境内货源地</td>
            <td><input type="text" class="textInput" id="addr_show"
                       name="declare.goods_addr" value="${declare.goods_addr}">
                <input id="addr" value="${declare.goods_addr}" type="hidden">
            </td>
        </tr>
        <tr>
            <td class="labelTD_80">批准文号</td>
            <td colspan="3"><input type="text" class="textInput" style="width:237px;"
                                   name="declare.approval_no" value="${declare.approval_no}" disabled="disabled"></td>
            <td class="labelTD_80">成交方式</td>
            <td><input type="text" class="textInput" id="deal_show"
                       name="declare.deal_mode" value="${declare.deal_mode}"> <input
                    name="" id="deal" value="${declare.deal_mode}"
                    type="hidden"></td>
            <td class="labelTD_80" colspan="4"></td>
        </tr>
        <tr>
            <td class="labelTD_80">运费</td>
            <td colspan="3"><input type="text" class="textInput" name="declare.freight1" id="freight1"
                                   style="width:230px;"
                                   title="计算类型" value="${declare.freight1}"></td>
            <td colspan="2">&nbsp;<input type="text" class="textInput" name="declare.freight2" style="width:200px;"
                                         title="数量" value="${declare.freight2}"></td>
            <td colspan="2"><input type="text" class="textInput" name="declare.freight3" style="width:200px;"
                                   title="币制" id="freight3_show" value="${declare.freight3}"> <input
                    type="hidden" class="textInput" name="" title="币制"
                    id="freight3" value="${declare.freight3}"></td>
            <td class="labelTD_80" colspan="2"></td>
        </tr>
        <tr>
            <td class="labelTD_80">保费</td>
            <td colspan="3"><input type="text" class="textInput" name="declare.premium1" id="premium1"
                                   style="width:230px;"
                                   title="同上" value="${declare.premium1}"></td>
            <td colspan="2">&nbsp;<input type="text" class="textInput" name="declare.premium2" style="width:200px;"
                                         title="同上" value="${declare.premium2}"></td>
            <td colspan="2"><input type="text" class="textInput" name="declare.premium3" style="width:200px;"
                                   title="同上" id="premium3_show" value="${declare.premium3}"> <input
                    type="hidden" class="textInput" name="" title="同上"
                    id="premium3" value="${declare.premium3}"></td>
            <td class="labelTD_80" colspan="2"></td>
        </tr>
        <tr>
            <td class="labelTD_80">杂费</td>
            <td colspan="3"><input type="text" class="textInput" title="同上" style="width:230px;"
                                   name="declare.otherfee1" id="otherfee1" value="${declare.otherfee1}"></td>
            <td colspan="2">&nbsp;<input type="text" class="textInput" title="同上" style="width:200px;"
                                         name="declare.otherfee2" value="${declare.otherfee2}"></td>
            <td colspan="2"><input type="text" class="textInput" title="同上" style="width:200px;"
                                   id="otherfee3_show" name="declare.otherfee3"
                                   value="${declare.otherfee3}"> <input type="hidden"
                                                                        class="textInput" title="同上" id="otherfee3"
                                                                        name=""
                                                                        value="${declare.otherfee3}"></td>
            <td class="labelTD_80" colspan="2"></td>
        </tr>
        <tr>
            <td class="labelTD_80">合同协议号</td>
            <td><input type="text" class="textInput" id="contract_no"
                       name="declare.contract_no" maxlength="20" style="width:80px;"
                       title="最长20个字符" onblur="javascript:getPi(this.value);"></td>
            <td class="labelTD_40">件数</td>
            <td><input type="text" class="textInput"
                       name="declare.goods_count" value="${declare.goods_count}" style="width:122px;"></td>
            <td class="labelTD_80">包装种类</td>
            <td><input type="text" class="textInput" id="packet_type"
                       name="declare.goods_package" value="${declare.goods_package}"></td>
            <td class="labelTD_80">毛重（KG）</td>
            <td><input type="text" class="textInput"
                       name="declare.gross_weight" value="${declare.gross_weight}"></td>
            <td class="labelTD_80">净重（KG）</td>
            <td><input type="text" class="textInput"
                       name="declare.net_weight" value="${declare.net_weight}"></td>
        </tr>
        <tr>
            <td class="labelTD_80">集装箱号</td>
            <td colspan="3"><input type="text" class="textInput" style="width:232px;" disabled="disabled"
                                   name="declare.container_no" value="${declare.container_no}"></td>
            <td class="labelTD_80">随附单证</td>
            <td colspan="2"><input type="text" class="textInput" style="width:150px;" name="declare.suifudan"
                                   value="${declare.suifudan}" disabled="disabled"></td>
            <td class="labelTD_80">生产厂家</td>
            <td colspan="2"><input type="text" class="textInput" style="width:150px;" name="declare.produce_factory"
                                   value="${declare.produce_factory }"></td>
        </tr>
        <tr>
            <td class="labelTD" rowspan="3">标记唛码及备注</td>
            <td colspan="9" rowspan="3"><input type="text" class="textInput" id="remark"
                                               name="declare.remark" style="width: 880px;height:40px"
                                               value="${declare.remark}"></td>
        </tr>
        <tr></tr>
        <tr></tr>
    </table>

    <div class="a">
        <table rules="rows" id="goodsListTB" class="dataTB dataTB_Individual" border="1">
            <tr class="titleTR" title="选中记录后，Ctrl+Z复制记录，Ctrl+U向上移动记录，Ctrl+I插入记录">
                <td class="titleTD" style="width: 40px; display:none" lang='declara_num'>序号</td>
                <td class="titleTD" style="width: 60px;" lang='code_t'>商品编号</td>
                <td class="titleTD" style="width: 60px;" lang="code_s">附加编号</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="record_id">备案序号</td>
                <td class="titleTD" style="width: 90px;" lang="name_mode">商品名称、规格型号</td>
                <td class="titleTD" style="width: 90px; display: none;" lang="name">商品名称</td>
                <td class="titleTD" style="width: 90px; display: none;" lang="goods_mode">规格</td>
                <td class="titleTD" style="width: 50px; display: none;" lang="count">成交数量</td>
                <td class="titleTD" style="width: 50px; display: none;" lang="unit">成交单位</td>
                <td class="titleTD" style="width: 150px;" lang="legal_count_1">数量及单位</td>
                <td class="titleTD" style="width: 50px; display: none;" lang="legal_count">法定数量</td>
                <td class="titleTD" style="width: 50px; display: none;" lang="legal_unit">法定单位</td>
                <td class="titleTD" style="width: 90px;" lang="destination">最终目的国(地区)</td>
                <td class="titleTD" style="width: 60px;" lang="unit_price">单价</td>
                <td class="titleTD" style="width: 70px;" lang="total_price">总价</td>
                <td class="titleTD" style="width: 70px;" lang="currency">币制</td>
                <td class="titleTD" style="width: 70px;" lang="levymode">征免</td>
                <td class="titleTD" style="width: 50px; display: none;" lang="processing_fee">工缴费</td>
                <!-- 				<td class="titleTD" style="width: 60px; display: none;" lang="code_s">附加编号</td> -->
                <td class="titleTD" style="width: 60px; display: none;" lang="version_no">版本号</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="second_count">第二数量</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="second_unit">第二单位</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="goods_no">货号</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="producer">生产厂家</td>
                <td class="titleTD" style="width: 60px;">操作</td>

                <td class="titleTD" style="width: 60px; display: none;" lang="">附加编号位置</td>
                <td class="titleTD" style="width: 60px; display: none;" lang="id">主键</td>
            </tr>
            <s:if test="%{declare==null }">
                <tr>
                    <td class="titleTD" style="width: 35px; display: none;"
                        lang="declara_num"><input style="width: 35px;"
                                                  id="goods_declara_num" name="declara_num" type="text"
                                                  value="<s:property
							value="0" />"/></td>
                    <td style="width: 86px;" lang="code_t"><input
                            id="goods_code_t" name="code_t" style="width: 80px;" type="text"
                            value="<s:property
							value="code_t" />"/></td>
                    <td style="width: 68px;" lang="code_s"><input
                            id="goods_code_s_1" style="width: 60px;" type="text"
                            value="<s:property
							value="code_s" />"/></td>
                    <td style="width: 86px; display: none;" lang="record_id"><input
                            id="goods_record_id_1" style="width: 80px;" disabled="disabled"
                            type="text" value="<s:property
							value="record_id" />"/></td>
                    <td style="width: 160px;" lang="name_mode">
						<span><input id="goods_name_1_1" style="width: 150px;" type="text"
                                     value="<s:property value="name" />"/></span>
						<span><input id="goods_goods_mode_1_1" style="width: 150px;" readonly="readonly"
                                     type="text" value="<s:property value="goods_mode" />"/></span>&nbsp;
						<span><input id="goods_count_1_1" style="width: 70px;" disabled="disabled" type="text"
                                     value="<s:property value="count" />"/></span>&nbsp;
						<span><input id="goods_unit_1_1" style="width: 70px;" disabled="disabled" type="text"
                                     value="<s:property value="unit" />"/></span>
                    </td>
                    <td style="width: 80px; display: none;" lang="name">
                        <input id="goods_name_1" style="width: 70px;" type="text"
                               value="<s:property value="name" />"/>
                    </td>
                    <td style="width: 133px; display: none;" lang="goods_mode"><input
                            id="goods_goods_mode_1" style="width: 125px;" disabled="disabled"
                            type="text" value="<s:property
							value="goods_mode" />"/></td>
                    <td style="width: 68px; display: none;" lang="count"><input id="goods_count_1"
                                                                                style="width: 60px;" type="text"
                                                                                value="<s:property
							value="count" />"/></td>
                    <td style="width: 68px; display: none;" lang="unit"><input id="goods_unit_1"
                                                                               style="width: 60px;" type="text"
                                                                               value="<s:property
							value="unit" />"/></td>
                    <td style="width: 136px;" lang="legal_count_1"><span><input
                            id="goods_legal_count_1_1" style="width: 60px;" readonly="readonly" type="text"
                            value="<s:property
							value="legal_count" />"/></span>&nbsp;<span><input
                            id="goods_legal_unit_1_1" style="width: 60px;" readonly="readonly" type="text"
                            value="<s:property
							value="legal_unit" />"/></span><span><input
                            id="goods_second_count_1_1" style="width: 60px;" readonly="readonly" type="text"
                            value="<s:property
							value="second_count" />"/></span>&nbsp;<span><input
                            id="goods_second_unit_1_1" style="width: 60px;" readonly="readonly" type="text"
                            value="<s:property
							value="second_unit" />"/></span></td>
                    <td style="width: 68px; display: none;" lang="legal_count"><input
                            id="goods_legal_count_1" style="width: 60px;" type="text"
                            value="<s:property
							value="legal_count" />"/></td>
                    <td style="width: 68px; display: none;" lang="legal_unit"><input
                            id="goods_legal_unit_1" style="width: 60px;" type="text"
                            value="<s:property
							value="legal_unit" />"/></td>
                    <td style="width: 83px;" lang="destination"><input
                            id="goods_destination_show_1" style="width: 80px;" type="text"
                            value="<s:property
							value="destination" />"/></td>
                    <td style="width: 68px;" lang="unit_price"><input
                            id="goods_unit_price_1" style="width: 60px;" type="text"
                            value="<s:property
							value="unit_price" />"/></td>
                    <td style="width: 68px;" lang="total_price"><input
                            id="goods_total_price_1" style="width: 60px;" type="text"
                            value="<s:property
							value="total_price" />"/></td>
                    <td style="width: 68px;" lang="currency"><input
                            id="goods_currency_show_1" style="width: 60px;" type="text"
                            value="<s:property
							value="currency" />"/></td>
                    <td style="width: 68px;" lang="levymode"><input
                            id="declareLevymode_1" style="width: 60px;" type="text"
                            value="<s:property
							value="levymode" />"/></td>
                    <td style="width: 68px; display: none;" lang="processing_fee"><input
                            id="goods_processing_fee_1" style="width: 60px;" type="text"
                            value="<s:property
							value="processing_fee" />"/></td>
                    <!-- 					<td style="width: 68px; display: none;" lang="code_s"><input -->
                    <!-- 						id="goods_code_s" style="width: 60px;" type="text" -->
                        <%-- 						value="<s:property --%>
                        <%-- 							value="code_s" />" /></td> --%>
                    <td style="width: 68px; display: none;" lang="version_no"><input
                            id="goods_version_no_1" style="width: 60px;" type="text"
                            value="<s:property
							value="version_no" />"/></td>
                    <td style="width: 68px; display: none;" lang="second_count"><input
                            id="goods_second_count_1" style="width: 60px;" type="text"
                            value="<s:property
							value="second_count" />"/></td>
                    <td style="width: 68px; display: none;" lang="second_unit"><input
                            id="goods_second_unit_1" style="width: 60px;" type="text"
                            value="<s:property
							value="second_unit" />"/></td>
                    <td style="width: 68px; display: none;" lang="goods_no"><input
                            id="goods_goods_no_1" style="width: 60px;" type="text"
                            value="<s:property
							value="goods_no" />"/></td>
                    <td style="width: 68px; display: none;" lang="producer"><input
                            id="goods_producer_1" style="width: 60px;" type="text"
                            value="<s:property
							value="producer" />"/></td>
                    <td style="width: 180px; cursor: pointer;"><u><span
                            id="confirmDeclare" style="color: #00007f; display: inline;"
                            onclick="confirmDeclare(this)">确认</span></u>|| <u><span
                            id="modiDeclare" style="color: #00007f;"
                            onclick="modiDeclare(this)">修改</span></u>|| <u><span
                            id="delDeclare" style="color: #00007f;"
                            onclick="delDeclare(this)">删除</span></u>|| <u><span
                            style="color: #00007f;" onclick="copyDeclare(this)">复制</span></u> <span
                            id="addDeclare" style="color: #00007f; display: none;"
                            onclick="addDeclare();">||<u>添加</u></span></td>
                    <td style="width: 68px; display: none;" lang=""><input id=""
                                                                           style="width: 60px;" type="text"
                                                                           value="<s:property
							value="" />"/></td>
                    <td style="width: 68px; display: none;" lang="id"><input
                            id="id" style="width: 60px;" type="text"
                            value="<s:property
							value="id" />"/></td>
                </tr>
            </s:if>
            <s:iterator value="declare.commodities" status="st">
                <tr class="titleTR1" id='declara_num_<s:property value="#st.index"/>'
                    style="cursor: pointer;">
                    <td class="titleTD" style="width: 35px; display: none;" lang="declara_num"><s:property
                            value="#st.index"/></td>
                    <td style="width: 80px;" lang="code_t"><s:property
                            value='code_t'/></td>
                    <td style="width: 60px;;" lang="code_s"><s:property
                            value="code_s"/></td>
                    <td style="width: 80px; display: none" lang="record_id"><s:property
                            value="record_id"/></td>
                    <td style="width: 160px;" lang="name_mode"><span><s:property
                            value="name"/></span>&nbsp;<br/>
                        <span><s:property value="goods_mode"/></span>&nbsp;<br/>
                        <span><s:property value="count"/></span>&nbsp;<span><s:property value="unit"/></span></td>
                    <td style="width: 150px; display: none;" lang="name"><s:property
                            value="name"/></td>
                    <td style="width: 125px; display: none;" lang="goods_mode"><s:property
                            value="goods_mode"/></td>
                    <td style="width: 60px; display: none;" lang="count"><s:property
                            value="count"/></td>
                    <td style="width: 60px; display: none;" lang="unit"><s:property
                            value="unit"/></td>
                    <td style="width: 130px;" lang="legal_count_1"><span><s:property
                            value="legal_count"/></span>&nbsp;<span><s:property value="legal_unit"/></span>&nbsp;<br/>
                        <span><s:property value="second_count"/></span>&nbsp;<span><s:property
                                value="second_unit"/></span></td>
                    <td style="width: 60px; display: none;" lang="legal_count"><s:property
                            value="legal_count"/></td>
                    <td style="width: 60px; display: none;" lang="legal_unit"><s:property
                            value="legal_unit"/></td>
                    <td style="width: 80px;" lang="destination"><s:property
                            value="destination"/></td>
                    <td style="width: 60px;" lang="unit_price"><s:property
                            value="unit_price"/></td>
                    <td style="width: 60px;" lang="total_price"><s:property
                            value="total_price"/></td>
                    <td style="width: 60px;" lang="currency"><s:property
                            value="currency"/></td>
                    <td style="width: 60px;" lang="levymode"><s:property
                            value="levymode"/></td>
                    <td style="width: 60px; display: none;" lang="processing_fee"><s:property
                            value="processing_fee"/></td>
                        <%-- 					<td style="width: 60px; display: none;" lang="code_s"><s:property --%>
                        <%-- 							value="code_s" /></td> --%>
                    <td style="width: 60px; display: none;" lang="version_no"><s:property
                            value="version_no"/></td>
                    <td style="width: 60px; display: none;" lang="second_count"><s:property
                            value="second_count"/></td>
                    <td style="width: 60px; display: none;" lang="second_unit"><s:property
                            value="second_unit"/></td>
                    <td style="width: 60px; display: none;" lang="goods_no"><s:property
                            value="goods_no"/></td>
                    <td style="width: 60px; display: none;" lang="producer"><s:property
                            value="producer"/></td>
                    <td style="width: 180px;"><u><span id="confirmDeclare" style="color: #00007f;"
                                                       onclick="confirmDeclare(this)">确认</span></u>||
                        <u><span id="modiDeclare" style="color: #00007f;" onclick="modiDeclare(this)">修改</span></u>||
                        <u><span id="delDeclare" style="color: #00007f;" onclick="delDeclare(this)">删除</span></u>||
                        <u><span id="modiDeclare" style="color: #00007f;" onclick="copyDeclare(this)">复制</span></u>
                        <span id="addDeclare" style="color: #00007f;display:none;"
                              onclick="addDeclare();">||<u>添加</u></span></td>
                    <td style="width: 60px; display: none;" lang=""></td>
                    <td style="width: 60px; display: none;" lang="id"><s:property value="id"/></td>
                </tr>
            </s:iterator>
        </table>
    </div>
    <table style="width: 97%" class="dataTB dataTB_Individual">
        <tr>
            <td class="labelTD_80" colspan="5"
                style="height: 30px; background-color: #F2F5F7; border: none; color: red">总价汇总：
            </td>
            <td id="gTotal" class="goodsInput disableInput" style="color: red;"></td>
        </tr>
    </table>


    <script>
        //载入页面时会从一个ajax获取数据
        var zhengMian;
        var arrivedCountryMode1;

        var goodsCurrencyMode1;
        //在征免那里触动自动下拉框
        function autoZhengMian(obj) {
            var datasource = new Array();
            $.each(zhengMian, function (i, n) {
                datasource.push(n.code + " " + n.name);
            });
            $(obj).autocomplete({
                minLength: 0, source: datasource,
                autoFocus: true, delay: 0, select: function (event, ui) {
                    var s = ui.item.label;
// 				$(obj).val(s.substring(0, s.indexOf(" ")));
                    $(obj).val(s.substring(s.indexOf(" ") + 1, s.length));
                    return false;
                }
            });
            $(obj).bind("focus", function (event) {
                $(obj).autocomplete("search");
            });
            $(obj).bind("click", function (event) {
                $(obj).autocomplete("search");
            });
        }
        $(function () {
            $("#reportDate").datepicker();
            var length = $("#goodsListTB tr").length - 1;
            var span = $("#goodsListTB tr:eq(" + length + ") td:eq(23) span:eq(4)");
            span.css("display", "inline");
            //若是商品列表只有一列 则将删除按钮的点击事件无效
            if (length == 1) {
                $("#goodsListTB tr:eq(1) td:eq(23) u:eq(2) span").attr("onclick", "return false;");
            } else {
                var spanObj = $("#goodsListTB tr:gt(0) td:eq(23) u:eq(2) span");
                $(spanObj).each(function (i, n) {
                    $(this).attr("onclick", "delDeclare(this)");
                });
            }
            var uObj = $(span).find("u");
// 		confirmDeclare(uObj);
// 		modiDeclare(uObj);
            triggerEnterEvent();
// 		autoMethod($("#declareCode_t"));//在另外地方执行
// 		autoZhengMian($("#declareLevymode"));


        });
        //订单列表的商品编号的自动事件生成
        var code_t_old = "";
        var code_s_old = "";
        function autoMethod(inputObj, type) {

            $(inputObj).autocomplete({
                minLength: 2,
                autoFocus: true,
                matchContains: true,
                source: function (request, response) {
                    var data = {k: $(inputObj).val()};
                    $.ajax({
                        url: "goodscode-findGoodsCode?tdateaa=" + timeNum(),
                        data: data,
                        success: function (data) {
                            codes = data.codes;
                            response($.map(data.codes, function (item) {
                                return {
                                    label: item.CODE_T + "." + item.CODE_S + item.g_NAME,
                                    CODE_S: item.CODE_S, CODE_T: item.CODE_T,
                                    GOODS_MODE: item.GOODS_MODE, UNIT_1: item.UNIT_1,
                                    UNIT_2: item.ILOW_PRICE, G_NAME: item.g_NAME
                                };
                            }));
                        }
                    });
                }, select: function (event, ui) {
                    var code_t = ui.item.CODE_T;
                    var code_s = ui.item.CODE_S;
                    $(this).val(ui.item.CODE_T);
                    //修改时获取code_t_old、code_s_old的值
                    code_t_old = $(inputObj).val();
                    code_s_old = $(inputObj).parents("tr").find("td:eq(2)").find("input").val();
// 				var declara_num_val = $(inputObj).find("td:eq(0)").find("input").val();
// 				alert("declara_num_val==="+declara_num_val);
                    if (code_t_old == code_t && code_s_old == code_s) {
                        isEdit = 1;
                        //加了个参数inputObj用于辨别订单列表的位置
                        loadGoodsCode(ui.item, isEdit, inputObj, type);
                    } else {
                        isEdit = 2;
                        loadGoodsCode(ui.item, isEdit, inputObj, type);
                    }
                    code_t_old = ui.item.CODE_T;
                    code_s_old = ui.item.CODE_S;
                    return false;
                }
            });
            //保证选择后，再点击能够加载表格
            $(inputObj).on("focus", function () {
                $(this).autocomplete("search");
            });
        }
        //隐藏添加按钮
        function hiddenAdd() {
            var length = $("#goodsListTB tr").length;
            for (var i = 1; i < length; i++) {
                var span = $("#goodsListTB tr:eq(" + i + ") td:eq(23) span:eq(4)");
                if (i == length - 1) {
                    span.css("display", "inline");
                } else {
                    span.css("display", "none");
                }
            }
        }
        //enter 事件的触发 用于各种获取焦点和转移焦点 用于商品列表修改方法
        function triggerEnterEvent() {
            $("input").each(function (index) {
                $(this).bind("keydown", function (event) {
                    var inputId = $(this).attr("id");
                    var declara_num = $(event.target.parentNode.parentElement).find("td:eq(0)").find("input").val();
                    if (declara_num == 0) {
                        declara_num = 1;
                    }
                    if (event.keyCode == 13) {
                        var posi = index;
                        if ($("#goodsModeInputTB tr").length == 0) {
                            if (inputId == "goods_name_1_" + declara_num) {
                                changeInputTo(posi - 3);
                            } else if (inputId == "goods_destination_show_" + declara_num) {
                                changeInputTo(posi + 2);
                            } else if (inputId == "goods_total_price_" + declara_num) {
                                var count = new Number($("#goods_count_" + declara_num).val());
                                var price = new Number($("#goods_total_price_" + declara_num).val());
                                var unit_price = Math.round((price / count) * 10000) / 10000;
                                $("#goods_unit_price_" + declara_num).val(unit_price);
                                changeInputTo(posi + 1);
                            }
                            changeInputTo(posi + 1);
                        }
                    }
                });
            });
        }
        //复制
        function copyDeclare(Obj) {
// 		var trObj = $(Obj).parent().parent().parent();
            var trObj = $(Obj).parents("tr");
// 		var length = $("#goodsListTB tr").length-1;
            //注意了由于用clone（true）方法的时候  父tr和子tr上的事件会互相影响  即使其中一个无效 则全部无效   故需重新定义
            trObj.clone(true).appendTo($("#goodsListTB"));
            var inputCount = $(trObj).find("td").eq(1).find("input").length;
            if (inputCount > 0) {
                confirmDeclare(Obj);
                modiDeclare(Obj);
            }
            var length = $("#goodsListTB tr").length - 1;
            var spanObj = $("#goodsListTB tr:eq(" + length + ") td:eq(23) u:eq(2)");
            //设置新复制的记录的declara_num
            $("#goodsListTB tr:last td:eq(0)").text(length - 1);
            confirmDeclare(spanObj);
            modiDeclare(spanObj);
// 		var tds = $("#goodsListTB tr").eq(length).find("td");
// 		for(var i=0;i<tds.length;i++){
// 			if($(tds[i]).find("input").length!=0){
// 				var tempStr = $(tds[i]).find("input").val();
// 				$(tds[i]).html("");
// 				$(tds[i]).text(tempStr);
// 			}
// 		}
            if (length == 1) {
                $("#goodsListTB tr:eq(1) td:eq(23) u:eq(2) span").attr("onclick", "return false;");
            } else {
                var trObj = $("#goodsListTB tr:gt(0)");
                $(trObj).each(function (i, n) {
                    $(this).find("td").eq(23).find("u").eq(2).find("span").attr("onclick", "delDeclare(this)");
                });
            }
            //清除复制时最新记录id的值
            $("#goodsListTB tr:last td:eq(25)").text("");

            triggerEnterEvent();
            hiddenAdd();
        }
        //确认
        function confirmDeclare(obj) {
// 		var tds = obj.parentNode.parentNode.parentNode.childNodes;
// 		$(tds).each(function(i,n){
// 			$(this).find("input").attr("disabled",true);
// 		});
// 		var tds = obj.parentNode.parentNode.parentNode.childNodes;
            var tds = $(obj).parents("tr").children();
            var declara_num_val = $(tds[0]).find("input").val();
            var declara_num = parseInt(declara_num_val) + 1;//获取当前选择tr所处的行数
            var goods_name_1_val = $("#goods_name_1_" + declara_num).val();
            if (goods_name_1_val == "") {//检测商品名称是否为空
                alert("商品名称不能为空!");
                $("#goods_name_1_" + declara_num).focus();
                $("#goods_name_1_" + declara_num).select();
                return;
            } else {
                $("#goods_name_" + declara_num).val(goods_name_1_val);//确认时设置商品名称的值
            }
            for (var i = 0; i < tds.length; i++) {
                if ($(tds[i]).find("input").length != 0) {
                    var tempStr = $(tds[i]).find("input").val();
                    if ($(tds[i]).attr("lang") == "name_mode") {
// 					var langName = $(tds[i]).attr("lang");
                        var goodsName = "";
                        var goodsGoodsMode = "";
                        var goodsCount = "";
                        var goodsUnit = "";
                        var inputId = "";
// 					$("td[lang='"+langName+"']").find("input").each(function(i,n) {
                        $("#goodsListTB tr:eq(" + declara_num + ") td:eq(4)").find("input").each(function (i, n) {
                            inputId = $(n).attr("id");
                            if (inputId == "goods_name_1_" + declara_num) {
                                goodsName = $(n).val();
                            } else if (inputId == "goods_goods_mode_1_" + declara_num) {
                                goodsGoodsMode = $(n).val();
                            } else if (inputId == "goods_count_1_" + declara_num) {
                                goodsCount = $(n).val();
                            } else if ("goods_unit_1") {
                                goodsUnit = $(n).val();
                            }
                        });
                        $(tds[i]).html("");
                        $(tds[i]).html("<span>" + goodsName + "</span>&nbsp;<br><span>" + goodsGoodsMode + "</span>&nbsp;<br/><span>" + goodsCount + "</span>&nbsp;<span>" + goodsUnit + "</span>");
                    } else if ($(tds[i]).attr("lang") == "legal_count_1") {
                        var countUnitName = $(tds[i]).attr("lang");
                        var goodsLegalCount = "";
                        var goodsLegalUnit = "";
                        var goodsSecondCount = "";
                        var goodsSecondUnit = "";
// 					$("td[lang='"+countUnitName+"']").find("input").each(function(i,n) {
                        $("#goodsListTB tr:eq(" + declara_num + ") td:eq(9)").find("input").each(function (i, n) {
                            inputId = $(n).attr("id");
                            if (inputId == "goods_legal_count_1_" + declara_num) {
                                goodsLegalCount = $(n).val();
                            } else if (inputId == "goods_legal_unit_1_" + declara_num) {
                                goodsLegalUnit = $(n).val();
                            } else if (inputId == "goods_second_count_1_" + declara_num) {
                                goodsSecondCount = $(n).val();
                            } else if (inputId == "goods_second_unit_1_" + declara_num) {
                                goodsSecondUnit = $(n).val();
                            }
                        });
                        $(tds[i]).html("");
                        $(tds[i]).html("<span>" + goodsLegalCount + "</span>&nbsp;<span>" + goodsLegalUnit + "</span>&nbsp;<br/><span>" + goodsSecondCount + "</span>&nbsp;<span>" + goodsSecondUnit + "</span>");
                    } else {
                        $(tds[i]).html("");
                        $(tds[i]).text(tempStr);
                    }
                }
            }


            refreshGoodsTotal();
        }
        //添加  还定义了各种下拉框事件
        function addDeclare() {
            var length = $("#goodsListTB tr").length - 1;
            var obj = $("#goodsListTB tr:eq(" + length + ")");
            obj.clone().appendTo($("#goodsListTB"));
            length = length + 1;
            //若是商品列表只有一列 则将删除按钮的点击事件无效
            if (length == 1) {
                $("#goodsListTB tr:eq(1) td:eq(23) u:eq(2) span").attr("onclick", "return false;");
            } else {
                var trObj = $("#goodsListTB tr:gt(0)");
                $(trObj).each(function (i, n) {
                    $(this).find("td").eq(23).find("u").eq(2).find("span").attr("onclick", "delDeclare(this)");
                });
            }
            var tds = $("#goodsListTB tr:eq(" + length + ") td");
            $(tds).each(function (i, n) {
                //按钮保留
                if (i == 23) {
// 				$(this).text("");
// 				var length1 = length-1;
// 				var str = "<u><span style='color: #00007f;'onclick='confirmDeclare("+length1+");'>确认</span></u>||<span style='color: #00007f;display:none;' onclick='addDeclare();'><u>添加</u>||</span><u><span style='color: #00007f;' onclick='modiDeclare("+length1+")'>修改</span></u>||<u><span style='color: #00007f;' onclick='delDeclare("+length1+")'>删除</span></u>";
// 				spanObns[1].click(function(){addDeclare();});
// 				spanObns[2].click(function(){modiDeclare(length);});
// 				spanObns[3].click(function(){delDeclare(6);});
// 				$(this).html(str);
                } else {
                    var width = n.style.width;
                    var idName = "goods_" + $(tds[i]).attr("lang") + "_" + length;
// 				var idName = "goods_" + $(tds[i]).attr("lang");
                    var langName = $(tds[i]).attr("lang");
                    $(this).html("");
                    $(tds[i]).html("<input id='" + idName + "' type='text'  value=''/>");
// 				$(tds[i]).find("input").css("width",width);

                    if (langName == "name_mode") {
                        $(tds[i]).html("");
                        $(tds[i]).html("<input type='text' style = 'width : 150px' id='goods_name_1_" + length + "' value=''/>&nbsp;<br/><input type='text' style = 'width : 150px' readonly = 'readonly' id='goods_goods_mode_1_" + length + "' value=''/>&nbsp;<br/><input type='text' style = 'width : 70px' disabled = 'disabled' id='goods_count_1_" + length + "' value=''/>&nbsp;<input type='text' style = 'width : 70px' disabled = 'disabled' id='goods_unit_1_" + length + "' value=''/>");
                    } else if (langName == "legal_count_1") {
                        $(tds[i]).html("");
                        $(tds[i]).html("<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_legal_count_1_" + length + "' value=''/>&nbsp;<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_legal_unit_1_" + length + "' value=''/>&nbsp;<br/><input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_second_count_1_" + length + "' value=''/>&nbsp;<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_second_unit_1_" + length + "' value=''/>");
                    } else {
                        $(this).html("");
                        $(tds[i]).html("<input id='" + idName + "' type='text' value=''/>");
                        $(tds[i]).find("input").css("width", width);
                    }
                    //设置declara_num的值
                    $(tds[0]).find("input").val(length - 1);
                    //规格 只读  备案序号只读
                    if (i == 5 || i == 3) {
                        $(tds[i]).find("input").attr("disabled", true);
                    }
                    //目的地下拉
                    if (i == 12) {
                        var destinationInputObj = $(tds[i]).find("input");
                        initDropDown(destinationInputObj, "", arrivedCountryMode1, 0);
                    }
                    if (i == 8) {//成交单位下拉框
                        var inputObj1 = $(tds[i]).find("input");
                        $(inputObj1).autocomplete({
                            minLength: 1, autoFocus: true, delay: 0,
                            source: unitData,
                            select: function (event, ui) {
                                var s = ui.item.label;
                                $(this).val(s.substring(s.indexOf(" ") + 1, s.length));
                                return false;
                            }
                        });
                    }
                    if (i == 10) {
                        var inputObj = $(tds[i]).find("input");
                        $(inputObj).autocomplete({
                            minLength: 1, autoFocus: true, delay: 0,
                            source: unitData,
                            select: function (event, ui) {
                                var s = ui.item.label;
                                $(this).val(s.substring(s.indexOf(" ") + 1, s.length));
                                return false;
                            }
                        });
                    }
                    if (i == 15) {//币制下拉框
                        var moneyRuleObj = $(tds[i]).find("input");
                        initDropDown(moneyRuleObj, "", goodsCurrencyMode1, 0);
                    }
                    if (i == 16) {//在征免部分添加下拉框事件
                        var inputObj = $(tds[i]).find("input");
                        autoZhengMian(inputObj);
                    }
                }
            });
            //商品编号添加自动生成下拉框事件
            var inputObj = $("#goodsListTB tr:eq(" + length + ") td:eq(1)").find("input");
            var type = "add";//类型为添加
            autoMethod(inputObj, type);
            triggerEnterEvent();
            hiddenAdd();
        }

        /**
         * 右键加载商品规格信息弹出框
         */
        function loadRightGoodsModeMenu(declara_num, obj) {
            var code_t_val = $(obj).parents("tr").find("td:eq(1)").find("input").val();
            var code_s_val = $(obj).parents("tr").find("td:eq(2)").find("input").val();
            var code_mode = "";
            isEdit = 1;
            type = "edit";
            $.ajax({
                url: "goodscode-findGoodsMode?tdateaa=" + timeNum(),
                type: "post",
                data: {code_t: code_t_val, code_s: code_s_val},
                success: function (data) {
                    code_mode = data.codes[0].GOODS_MODE;
                    loadGoodsMode(code_t_val, code_s_val, code_mode, isEdit, obj, type);
                }
            });
        }

        /**
         * 右键修改商品规格的弹出框
         */
        function createRightGoodsModeMenu(declara_num, obj) {
            var goodsMode = "<div class='contextMenu' id='rightgoodsModeMenu' style='display:none;'><ul><li id='goodsModeModify'>修改</li></ul></div>";
            $("body").append(goodsMode);
            $("#goods_goods_mode_1_" + declara_num).contextMenu('rightgoodsModeMenu', {
                bindings: {
                    'goodsModeModify': function (t) {
// 					loadGoodsOtherMode(declara_num);
                        loadRightGoodsModeMenu(declara_num, obj);
                    }
                },
                itemStyle: {
                    listStyleType: 'none',
                    fontFamily: '宋体',
                    fontSize: '12px',
                    color: '#000',
                    textIndent: '1em'
                }
            });
        }


        /**
         * 右键修改数量单位等信息弹出框
         */
        function createRightMenu(declara_num) {
            var d = "<div class='contextMenu' id='rightMenu' style='display:none;'><ul><li id='modify'>修改</li></ul></div>";
            $("body").append(d);

            $(
                    "#goods_legal_count_1_" + declara_num + ","
                    + "#goods_legal_unit_1_" + declara_num + ","
                    + "#goods_second_count_1_" + declara_num + ","
                    + "#goods_second_unit_1_" + declara_num)
                    .contextMenu('rightMenu', {
                        bindings: {
                            'modify': function (t) {
                                loadGoodsOtherMode(declara_num);
                            }
                        },
                        itemStyle: {
                            listStyleType: 'none',
                            fontFamily: '宋体',
                            fontSize: '12px',
                            color: '#000',
                            textIndent: '1em'
                        }
                    });
        }

        //修改   还定义了各种下拉框事件
        function modiDeclare(obj) {
            var tds = $(obj).parents("tr").children();
            var declara_num_val = $(tds[0]).text();
            var declara_num = parseInt(declara_num_val) + 1;//获取当前选择tr所处的行数
            var type = "edit";//类型为修改
            //tds应该选择了一些其他东西 未知
            for (var i = 0; i < tds.length, i != 23; i++) {
                if ($(tds[i]).find("input").length == 0) {
                    var width = $(tds[i]).width() - 10;
                    var tempStr = $(tds[i]).text();
                    var idName = "goods_" + $(tds[i]).attr("lang") + "_"
                            + declara_num;
                    // 				var idName = "goods_" + $(tds[i]).attr("lang");

                    var langName = $(tds[i]).attr("lang");
// 					if(langName != "name_mode" && langName != "legal_count_1") {
// 						$(tds[i])
// 								.html(
// 										"<input type='text' id='"+idName+"' value='"+tempStr+"'/>");
// 						$(tds[i]).find("input").css("width", width);
// 					}

                    if (langName == "name_mode") {
                        var goodsName = "";
                        var goodsGoodsMode = "";
                        var goodsCount = "";
                        var goodsUnit = "";
                        var arrayObj = new Array();
                        arrayObj = $("#goodsListTB tr:eq(" + declara_num + ") td:eq(4)")
                                .find("span");

                        goodsName = arrayObj[0].innerHTML;
                        goodsGoodsMode = arrayObj[1].innerHTML;
                        goodsCount = arrayObj[2].innerHTML;
                        goodsUnit = arrayObj[3].innerHTML;
                        $(tds[i]).html("");
                        $(tds[i])
                                .html(
                                        "<div><input type='text' style = 'width : 150px' id='goods_name_1_" + declara_num + "' value='" + goodsName + "'/></div><input type='text' style = 'width : 150px' readonly = 'readonly' id='goods_goods_mode_1_" + declara_num + "' value='" + goodsGoodsMode + "'/><br/><input type='text' style = 'width : 70px' disabled = 'disabled' id='goods_count_1_" + declara_num + "' value='" + goodsCount + "'/>&nbsp;<input type='text' style = 'width : 70px' disabled = 'disabled' id='goods_unit_1_" + declara_num + "' value='" + goodsUnit + "'/>");
                    } else if (langName == "legal_count_1") {
                        var goodsLegalCount = "";
                        var goodsLegalUnit = "";
                        var goodsSecondCount = "";
                        var goodsSecondUnit = "";
                        var arrayObj = new Array();
                        arrayObj = $("#goodsListTB tr:eq(" + declara_num + ") td:eq(9)").find("span");
                        goodsLegalCount = arrayObj[0].innerHTML;
                        goodsLegalUnit = arrayObj[1].innerHTML;
                        goodsSecondCount = arrayObj[2].innerHTML;
                        goodsSecondUnit = arrayObj[3].innerHTML;
                        $(tds[i]).html("");
                        $(tds[i])
                                .html(
                                        "<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_legal_count_1_" + declara_num + "' value='" + goodsLegalCount + "'/>&nbsp;<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_legal_unit_1_" + declara_num + "' value='" + goodsLegalUnit + "'/><br/><input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_second_count_1_" + declara_num + "' value='" + goodsSecondCount + "'/>&nbsp;<input type='text' style = 'width : 60px' readonly = 'readonly' id='goods_second_unit_1_" + declara_num + "' value='" + goodsSecondUnit + "'/>");
                    } else {
                        $(tds[i])
                                .html(
                                        "<input type='text' id='" + idName + "' value='" + tempStr + "'/>");
                        $(tds[i]).find("input").css("width", width);
                    }
                    if (i == 1) {
                        var inputObj = $(tds[i]).find("input");
                        autoMethod(inputObj, type);
                    }
                    //规格只读 备案序号只读
                    if (i == 5 || i == 3) {
                        $(tds[i]).find("input").attr("disabled", true);
                    }
                    //附加编号只读
                    if (i == 2) {
                        $(tds[i]).find("input").attr("disabled", true);
                    }
                    //目的地下拉框事件
                    if (i == 12) {
                        var destinationInputObj = $(tds[i]).find("input");
                        initDropDown(destinationInputObj, "",
                                arrivedCountryMode1, 0);
                    }
                    //成交单位下拉框
                    if (i == 8) {
                        var inputObj = $(tds[i]).find("input");
                        $(inputObj).autocomplete(
                                {
                                    minLength: 1,
                                    autoFocus: true,
                                    delay: 0,
                                    source: unitData,
                                    select: function (event, ui) {
                                        var s = ui.item.label;
                                        $(this).val(
                                                s.substring(s.indexOf(" ") + 1,
                                                        s.length));
                                        return false;
                                    }
                                });
                    }
                    //法定单位下拉框
                    if (i == 10) {
                        var inputObj = $(tds[i]).find("input");
                        $(inputObj).autocomplete(
                                {
                                    minLength: 1,
                                    autoFocus: true,
                                    delay: 0,
                                    source: unitData,
                                    select: function (event, ui) {
                                        var s = ui.item.label;
                                        $(this).val(
                                                s.substring(s.indexOf(" ") + 1,
                                                        s.length));
                                        return false;
                                    }
                                });
                    }
                    if (i == 15) {//币制下拉框事件
                        var moneyRuleObj = $(tds[i]).find("input");
                        initDropDown(moneyRuleObj, "", goodsCurrencyMode1, 0);
                    }
                    if (i == 16) {
                        var inputObj = $(tds[i]).find("input");
                        autoZhengMian(inputObj);
                    }
                }
            }
            triggerEnterEvent();
            createRightGoodsModeMenu(declara_num, obj);
            createRightMenu(declara_num);
        }
        //删除
        function delDeclare(obj) {
            obj.parentNode.parentNode.parentNode.remove();
            //若是商品列表只有一列 则将删除按钮的点击事件无效
            var length = $("#goodsListTB tr").length - 1;
            if (length == 1) {
                $("#goodsListTB tr:eq(1) td:eq(23) u:eq(2) span").attr(
                        "onclick", "return false;");
            } else {
                var spanObj = $("#goodsListTB tr:gt(0) td:eq(23) u:eq(2) span");
                $(spanObj).each(function (i, n) {
                    $(this).attr("onclick", "delDeclare(this)");
                });
            }
            hiddenAdd();
        }

        /**
         *总价汇总
         */
        function refreshGoodsTotal() {
            var currency = "";
            var sum = 0;
            $("#goodsListTB").find("tr").each(function (index) {
                if ($(this).attr("class") != "titleTR") {
                    $(this).find("td").each(function (tdindex) {
                        var datasrc = this;
                        var data = datasrc.innerText;
                        switch (tdindex) {
                            case 15:
                                currency = data;
                                break;
                            case 14:
                                sum = data - (-sum);
                                break;
                        }
                    });
                }
            });
            if (currency != "") {
                $("#gTotal")
                        .text(currency + " ：" + Math.round(sum * 100) / 100);
            } else {
                $("#gTotal").text("");
            }
        }
        refreshGoodsTotal();

        var modify_tr_id_goods = null;//用于记录当前需要编辑的商品行记录id
        var modify_tr_id_suifudan = null;//用于记录当前需要编辑的随附单行记录id
        var declara_num = 0;
        function confirm_declaraGoods() {
            var GOODS_RECORD_ID = $("#goods_record_id").val();//备案序号
            var GOODS_CODE_T = $("#goods_code_t").val(); //商品编号
            var GOODS_CODE_S = $("#goods_code_s").val();//附加编号
            var GOODS_NAME = $("#goods_name").val();//商品名称
            var GOODS_MODE = $("#goods_goods_mode").val();//规格型号
            var GOODS_DEAL_COUNT = $("#goods_count").val();//成交数量
            // 			var GOODS_UNIT = $("#goods_unit").val();//成交单位
            var GOODS_UNIT = $("#goods_unit_other").val();//成交单位
            var GOODS_UNIT_PRICE = $("#goods_unit_price").val();//成交单价
            var GOODS_TOTAL_PRICE = $("#goods_total_price").val();//成交总价
            var GOODS_CURRENCY = $("#goods_currency_show").val();//币制
            var GOODS_LEGAL_COUNT = $("#goods_legal_count").val();//法定数量
            var GOODS_LEGAL_UNIT = $("#goods_legal_unit").val();//法定单位
            var GOODS_VERSION_NO = $("#goods_version_no").val();//版本号
            var GOODS_GOODS_NO = $("#goods_goods_no").val();//货号
            var GOODS_PRODUCER = $("#goods_producer").val();//生产厂家
            var GOODS_SECOND_COUNT = $("#goods_second_count").val();//第二数量
            var GOODS_SECOND_UNIT = $("#goods_second_unit").val();//第二单位
            var GOODS_DESTINATION = $("#goods_destination_show").val();//目的地
            var GOODS_LEVYMODE = $("#goods_levymode").val();//征免
            var GOODS_PROCESSING_FEE = $("#goods_processing_fee").val();//工缴费
            var GOODS_ID = $("#goods_id").val();//主键

            //if(!GOODS_RECORD_ID)return;
            if (!GOODS_NAME || !GOODS_CODE_T) {
                alert("请填写商品名称和商品编号");
                return;
            }

            if (!($("#goods_declara_num").val())) {
                declara_num++;
            }

            var tdconnect = "";
            if ($("#goods_declara_num").val()) { //  修改操作
                tdconnect = tdconnect + "<td lang='declara_num'>"
                        + $("#goods_declara_num").val() + "</td>";
            } else { //新增操作
                tdconnect = tdconnect + "<td lang='declara_num'>" + declara_num
                        + "</td>";
            }
            tdconnect = tdconnect + "<td lang='code_t'>" + GOODS_CODE_T
                    + "</td>";
            tdconnect = tdconnect + "<td lang='record_id'>" + GOODS_RECORD_ID
                    + "</td>";
            tdconnect = tdconnect + "<td lang='name'>" + GOODS_NAME + "</td>";
            tdconnect = tdconnect + "<td lang='goods_mode'>" + GOODS_MODE
                    + "</td>";
            tdconnect = tdconnect + "<td lang='destination'>"
                    + GOODS_DESTINATION + "</td>";
            tdconnect = tdconnect + "<td lang='count'>" + GOODS_DEAL_COUNT
                    + "</td>";
            tdconnect = tdconnect + "<td lang='unit'>" + GOODS_UNIT + "</td>";
            tdconnect = tdconnect + "<td lang='currency'>" + GOODS_CURRENCY
                    + "</td>";
            tdconnect = tdconnect + "<td lang='total_price'>"
                    + GOODS_TOTAL_PRICE + "</td>";
            tdconnect = tdconnect + "<td lang='levymode' class='hiddenValue'>"
                    + GOODS_LEVYMODE + "</td>";
            tdconnect = tdconnect + "<td lang='code_s' class='hiddenValue'>"
                    + GOODS_CODE_S + "</td>";
            tdconnect = tdconnect
                    + "<td lang='unit_price' class='hiddenValue'>"
                    + GOODS_UNIT_PRICE + "</td>";
            tdconnect = tdconnect
                    + "<td lang='legal_count' class='hiddenValue'>"
                    + GOODS_LEGAL_COUNT + "</td>";
            tdconnect = tdconnect
                    + "<td lang='legal_unit' class='hiddenValue'>"
                    + GOODS_LEGAL_UNIT + "</td>";
            tdconnect = tdconnect
                    + "<td lang='version_no' class='hiddenValue'>"
                    + GOODS_VERSION_NO + "</td>";
            tdconnect = tdconnect + "<td lang='goods_no' class='hiddenValue'>"
                    + GOODS_GOODS_NO + "</td>";
            tdconnect = tdconnect + "<td lang='producer' class='hiddenValue'>"
                    + GOODS_PRODUCER + "</td>";
            tdconnect = tdconnect
                    + "<td lang='second_count' class='hiddenValue'>"
                    + GOODS_SECOND_COUNT + "</td>";
            tdconnect = tdconnect
                    + "<td lang='second_unit' class='hiddenValue'>"
                    + GOODS_SECOND_UNIT + "</td>";
            tdconnect = tdconnect
                    + "<td lang='processing_fee' class='hiddenValue'>"
                    + GOODS_PROCESSING_FEE + "</td>";
            tdconnect = tdconnect + "<td class='hiddenValue'></td>";
            tdconnect = tdconnect + "<td lang='id' class='hiddenValue'>"
                    + GOODS_ID + "</td>";

            if ($("#goods_declara_num").val()) { //修改商品操作
                $("#" + modify_tr_id_goods).html("");
                $("#" + modify_tr_id_goods).html(tdconnect);
            } else { //添加商品操作
                tdconnect = "<tr onclick='edit(this);' style='cursor:pointer;' id='declara_num_"
                        + declara_num + "'>" + tdconnect + "</tr>";
                $("#goodsListTB").append(tdconnect);
            }

            $("#goods_declara_num").val("");
            $("#goodsInfoTB input:text").each(function (i) { //清空商品
                this.value = "";
            });
            modify_tr_id_goods = null;
            refreshGoodsTotal();
        }
        //赋予当前编辑数据
        function edit(obj) {
            if (obj.id.indexOf("suifudan") > -1) { //当前为编辑随附单
                modify_tr_id_suifudan = obj.id;
            } else {
                modify_tr_id_goods = obj.id;
            }
            modify_tr_id = obj.id;
            $
                    .each(
                            $(obj).find("td"),
                            function (i, n) {
                                $("#goods_" + $(this).attr("lang")).val(
                                        $(n).text());
                                if ("#goods_" + $(this).attr("lang") == "#goods_currency") {
                                    $("#goods_currency_show").val($(n).text());
                                } else if ("#goods_" + $(this).attr("lang") == "#goods_destination") {
                                    $("#goods_destination_show").val(
                                            $(n).text());
                                }

                            });
        }
    </script>
    <div id="goodsDiv">
        <div id="CODE_POSI" class="0"></div>
        <div style="float: left;">
            <!--  			<table id="goodsInfoTB" rules="rows" class="goodsInTB" style="display:none;">
				<tr>
					<td class="labelTD_80">备案序号</td>
					<td><input type="text" class="goodsInput" id="goods_record_id"
						disabled="disabled" /></td>
					<td class="labelTD_80">商品编号</td>
					<td>
							name="commodity.code_t"					<input type="text" class="goodsInput" id="goods_code_t" maxlength="8"  onfocus="initGoodsCodeEdit();"/>
-->
            <!-- 						<input type="text" class="goodsInput" id="goods_code_t" -->
            <%-- 						 value="${commodity.code_t }" maxlength="8" /> --%>
            <!-- 					onfocus="initGoodsCodeEdit();" <input type="hidden" -->
            <!-- 						class="goodsInput" id="goods_code_hide"  -->
            <%-- 						value="${commodity.code_t }" maxlength="8" /> --%>
            <!-- 					</td>
					<td class="labelTD_80">附加编号</td>
					<td><input type="text" class="goodsInput disableInput"
						disabled="disabled" id="goods_code_s" /></td>
				</tr>
				<tr>
					<td class="labelTD_80">商品名称</td>
					<td><input type="text" class="goodsInput" id="goods_name" /></td>
					<td class="labelTD_80">规格型号</td>
					<td colspan="3"><input type="text"
						class="goodsInput disableInput" id="goods_goods_mode"
						disabled="disabled" style="width: 339px;" /></td>
				</tr>
				<tr>
					<td class="labelTD_80">成交数量</td>
					<td><input type="text" class="goodsInput" id="goods_count" /></td>
					<td class="labelTD_80">成交单位</td>
					<td><input type="text" class="goodsInput" id="goods_unit" /></td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td class="labelTD_80">成交单价</td>
					<td><input type="text" class="goodsInput"
						id="goods_unit_price" /></td>
					<td class="labelTD_80">成交总价</td>
					<td><input type="text" class="goodsInput"
						id="goods_total_price" /></td>
					<td class="labelTD_80">币制</td>
					<td>
												<input type="text" class="goodsInput" id="goods_currency" />
						<input type="text" class="goodsInput" id="goods_currency_show" >
						<input type="hidden" class="goodsInput" id="goods_currency" >
					</td>
				</tr>
				<tr>
					<td class="labelTD_80">法定数量</td>
					<td><input type="text" class="goodsInput"
						id="goods_legal_count" /></td>
					<td class="labelTD_80">法定单位</td>
					<td><input type="text" class="goodsInput"
						id="goods_legal_unit" disabled="disabled" /></td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td class="labelTD_80">版本号</td>
					<td><input type="text" class="goodsInput"
						id="goods_version_no" /></td>
					<td class="labelTD_80">货号</td>
					<td><input type="text" class="goodsInput" id="goods_goods_no" /></td>
					<td class="labelTD_80" id="label_gproducer">生产厂家</td>
					<td><input type="text" class="goodsInput" id="goods_producer" /></td>
				</tr>
				<tr>
					<td class="labelTD_80">第二数量</td>
					<td><input type="text" class="goodsInput"
						id="goods_second_count" /></td>
					<td class="labelTD_80">第二单位</td>
					<td><input type="text" class="goodsInput"
						id="goods_second_unit"  /></td>
					<td></td>
					<td></td>
				</tr>
				<tr>
					<td class="labelTD_80" id="gdestination">目的地</td>
					<td>
												<input type="text" class="goodsInput" id="goods_destination" />
 -->
            <!-- 						<input type="text" class="goodsInput" name="declare.arrived_country" -->
            <!-- 						id="goods_destination_show" value=""> <input -->
            <!-- 						type="hidden" class="goodsInput" name="" -->
            <%-- 						id="goods_destination" value="${declare.arrived_country}"> --%>
            <!--					<input type="text" class="goodsInput" id="goods_destination_show"/>
					<input type="hidden" class="goodsInput" id="goods_destination"/>
					</td>
					<td class="labelTD_80">征免</td>
					<td><input type="text" class="goodsInput" id="goods_levymode" />
						<input class="goodsInput" id="goods_levymode_val" type="hidden" />
					</td>
					<td class="labelTD_80" id="gprocessing_fee">工缴费</td>
					<td><input type="text" class="goodsInput"
						id="goods_processing_fee" /> <input type="hidden"
						id="goods_declara_num" /> <input type="text"
						style="display: none;" id="goods_id" /></td>
				</tr>


				<tr>
					<td colspan="6" style="background-color: #dfe2f8"><input
						style="float: right; background-color: background-color:#dfe2f8"
						onclick="confirm_declaraGoods();" type="button" value="确认" id="queren1" /></td>
				</tr>
			</table>
  -->
        </div>
        <script>
            var suifudan_num = 0;
            function confirm_suifudan() {
                var SUIFUDAN_CO = $("#goods_suifudan_co").val();//随附单代码
                var SUIFUDAN_NO = $("#goods_suifudan_no").val(); //随附单编号
                var ID = $("#goods_id").val();//随附单主键

                if (!SUIFUDAN_CO && !SUIFUDAN_NO)
                    return;

                if (!($("#goods_suifudan_num").val())) {
                    suifudan_num++;
                }

                var tdconnect = "";
                tdconnect = tdconnect + "<td lang='suifudan_co'>" + SUIFUDAN_CO + "</td>";
                tdconnect = tdconnect + "<td lang='suifudan_no'>" + SUIFUDAN_NO + "</td>";
                tdconnect = tdconnect + "<td lang='suifudan_num' class='hiddenValue'>" + suifudan_num + "</td>";
                tdconnect = tdconnect + "<td lang='id' class='hiddenValue'>" + ID + "</td>";

                if ($("#goods_suifudan_num").val()) { //修改随附单操作
                    $("#" + modify_tr_id_suifudan).html("");
                    $("#" + modify_tr_id_suifudan).html(tdconnect);
                } else { //添加随附单操作
                    tdconnect = "<tr onclick='edit(this);' style='cursor:pointer;' id='suifudan_num_" + suifudan_num + "'>" + tdconnect + "</tr>";
                    $("#suifudanListTB").append(tdconnect);
                }

                $("#goods_suifudan_num").val("");
                $("#suifudanInfoTB input:text").each(function (i) { //清空随附单
                    this.value = "";
                });
                modify_tr_id_suifudan = null;
            }
        </script>
        <br>
        <div style="float: left; margin-left: 35px;">
            <table rules="rows" id="suifudanListTB"
                   class="dataTB righdataTB_Individual">
                <tr class="titleTR">
                    <!-- 					<td class="titleTD titleTD_Individual" lang="suifudan_co">随附单代码</td> -->
                    <td class="titleTD titleTD_Individual" lang="suifudan_co">随附单名称</td>
                    <td class="titleTD titleTD_Individual" lang="suifudan_no">随附单编号</td>
                    <td class="hiddenValue" lang="suifudan_num"></td>
                    <td class="hiddenValue" lang="id">主键</td>
                </tr>
                <s:iterator value="declare.suiFuDans" status="st">
                    <tr onclick="edit(this);" style="cursor: pointer;"
                        id="suifudan_num_<s:property value="#st.index"/>">
                        <td lang="suifudan_co"><s:property value="suifudan_co"/></td>
                        <td lang="suifudan_no"><s:property value="suifudan_no"/></td>
                        <td class="hiddenValue" lang="suifudan_num"><s:property
                                value="id"/></td>
                        <td class="hiddenValue" lang="id"><s:property value="id"/></td>
                    </tr>
                </s:iterator>
            </table>
            <table class="rightTB" id="suifudanInfoTB" rules="rows">
                <tr>
                    <!-- 					<td class="labelTD_80">随附单代码</td> -->
                    <td class="labelTD_80">随附单名称</td>
                    <td><input type="text" class="suifuInput"
                               id="goods_suifudan_co" style="width: 180px;"/></td>
                </tr>
                <tr>
                    <td class="labelTD_80">随附单编号</td>
                    <td><input type="text" class="suifuInput"
                               id="goods_suifudan_no" style="width: 180px;"/><input
                            type="hidden" id="goods_suifudan_num"/><input type="hidden"
                                                                          id="goods_id"/></td>
                </tr>
                <tr>
                    <td colspan="2" style="background-color: #dfe2f8"><input
                            style="float: right; background-color: background-color:#dfe2f8"
                            type="button" onclick="confirm_suifudan();" value="确认" id="queren2"/></td>
                </tr>
            </table>
            <table class="rightTB" id="otherInfoTB" rules="rows">
                <tr>
                    <td class="labelTD_80">关联报关单</td>
                    <td><input type="text" name="declare.re_manifest"
                               value="${declare.re_manifest}"></td>
                </tr>
                <tr>
                    <td class="labelTD_80">关联备案</td>
                    <td><input type="text" name="declare.re_record_id"
                               value="${declare.re_record_id}"></td>
                </tr>
                <tr>
                    <td class="labelTD_80">监管仓号</td>
                    <td><input type="text" name="declare.re_jianguan"
                               value="${declare.re_jianguan}"></td>
                </tr>
                <tr>
                    <td class="labelTD_80">货场代码</td>
                    <td><input type="text" name="declare.re_yard_id"
                               value="${declare.re_yard_id}"></td>
                </tr>
            </table>
        </div>

        <!-- 		商品规格弹出框 -->
        <div style="float:left;margin-left: 35px;">
            <table id="goodsModeInputTB" rules="rows" class="dataTB">
            </table>
        </div>
        <!-- 		版本号等其他信息弹出框 -->
        <div style="float:left;margin-left: 35px;">
            <table id="goodsModeOtherInputTB" rules="rows" class="dataTB">
            </table>
        </div>
        <div style="clear: both;"></div>
        <div id="containInfo">
            <table>
                <tr>
                    <td class="first_li">分柜资料附件：</td>
                </tr>
                <tr>
                    <td><s:if test="declare.containerInfo!= null"><s:property value="declare.containerInfo.name"/><input
                            type="button" value="删除附件" onclick="cancleUploadAccess();"/></s:if><s:else>上传</s:else></td>
                    <td><input id="" type="button" value="选择文件" onclick="uploadAccess();"/></td>
                </tr>
                <tr>
                    <!-- 	   	  		<td>SO号：</td> -->
                    <%-- 	   	  		<td><input type="text" class="textInput" id="" name="trial.so" value="${trial.so }"/></td> --%>
                </tr>
            </table>
        </div>
        <div id="" style="display:none;">
            SO信息：<span id=""></span><input name="declare.containerInfo.id"
                                           value="<s:property value="declare.containerInfo.id" />" id="containerInfoId"
                                           style="display:none;"/>
        </div>
        <div id="dialog002" style="display:none">
            <s:form id="uploadAccessoryForm" action="attach-upload" enctype="multipart/form-data" method="POST">
                <s:file label="选择文件" name="attach"></s:file>
                <s:submit value="上传"></s:submit>
            </s:form>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        //初始化上传功能
        var option = {
            success: function showResponse(responseText,
                                           statusText, xhr, $form) {
                jw.close();
                var responseText = eval("(" + responseText + ")");
                $("#containerInfoId").val(responseText.attachment.id);
                $("#containInfo table tr:eq(1) td:eq(0)").html(responseText.attachment.name);
            }
        };
        $("#uploadAccessoryForm").ajaxForm(option);
    });
    //上传分柜附件
    function uploadAccess() {
        var param = {
            id: '#dialog002'
        };
        jw.dialog(param);
    }
    //取消上传分柜附件
    function cancleUploadAccess() {
        var fileId = $("#containerInfoId").val();
        if (fileId) {
            $.ajax({
                url: "attach-cancleFile?fileId=" + fileId,
                success: function (data) {
                    var msg = $.parseJSON(data.msg);
                    jw.alert(msg.msg);
                    if (msg.state == "1") {
                        //$("#uploadForm").attr("enctype","multipart/form-data");
                        $("#containInfo table tr:eq(1) td:eq(0)").html("上传");
                        $("#containerInfoId").val("");
                    }
                }
            });
        } else {
            jw.alert("没有已上传文件！");
        }
    }
    //报关报检业务代理人
    $(function () {
        $('input[title!=""]').hint();
        $("#declaration_sup_id").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "business-findCompanysByNameType",
                    dataType: "json",
                    type: "post",
                    data: {
                        com_type: "CC", sup_type: "D",//报关业务类型
                        com_name: request.term
                    },
                    success: function (data) {
                        response($.map(data.companys, function (item) {
                            return {
                                id: item.id, name: item.name,
                                value: item.name
                            };
                        }));
                    }
                });
            },
            minLength: 0,
            select: function (event, ui) {
                $("#declaration_sup").val(ui.item.id);
            },
            change: function (event, ui) {
                var declaration_sup_id = $("#declaration_sup_id").val();
                $.ajax({
                    url: "business-findCompanysByNameTypeIsRight",
                    dataType: "json",
                    type: "post",
                    data: {
                        com_type: "CC", sup_type: "D",//订舱业务类型
                        com_name: declaration_sup_id
                    },
                    success: function (data) {
                        if (data.companys == "") {
                            alert("请在报关报检业务代理人的下拉框中选择报关报检业务代理人！");
                            $("#declaration_sup_id").focus();
                        } else {
                            var declaration_sup_id = $("#declaration_sup_id").val();
                            var declaration_sup = $("#declaration_sup").val();
                            if (declaration_sup_id != "" && declaration_sup == "") {
                                alert("请在报关报检业务代理人的下拉框中选择报关报检业务代理人！");
                                $("#declaration_sup_id").focus();
                            }
                        }
                    }
                });
            }
        });

        $("#declaration_sup_id").bind("click", function () {
            $(this).autocomplete('search', '');
        });
    });

    //提交
    function submit_decla() {
        //报关商品
        var decla_goods_trs = $("#goodsListTB tr");
        if (decla_goods_trs.length > 1) {
            var temp_tr0_tds = $(decla_goods_trs[0]).find("td");
            var index = 0;
            var temp_goodsInput = "";
            for (var i = 1; i < decla_goods_trs.length; i++) {
                var dGoodsTds = $(decla_goods_trs[i]).find("td");
                for (var j = 0; j < temp_tr0_tds.length; j++) {
                    if ($(temp_tr0_tds[j]).attr("lang") && $(temp_tr0_tds[j]).attr("lang") != "declara_num") {
                        var dGoodsInputs = $(dGoodsTds[j]).find("input");
                        if (dGoodsInputs.length != 0) {
                            temp_goodsInput = temp_goodsInput
                                    + "<input type='hidden' name='declare.commodities[" + index + "]."
                                    + $(temp_tr0_tds[j]).attr("lang")
                                    + "' value=\"" + $(dGoodsInputs).val() + "\" \/>";
                        } else {
                            temp_goodsInput = temp_goodsInput
                                    + "<input type='hidden' name='declare.commodities[" + index + "]."
                                    + $(temp_tr0_tds[j]).attr("lang")
                                    + "' value=\"" + $(dGoodsTds[j]).text() + "\" \/>";
                        }
                    }
                }
                index++;
            }
            $("#input_declare_goods").html("");
            $("#input_declare_goods").html(temp_goodsInput);
        }
        //报关随附单
        var decla_suifu_trs = $("#suifudanListTB tr");
        if (decla_suifu_trs.length > 1) {
            var temp_tr0_tds = $(decla_suifu_trs[0]).find("td");
            var index = 0;
            var temp_goodsInput = "";
            for (var i = 1; i < decla_suifu_trs.length; i++) {
                var dGoodsTds = $(decla_suifu_trs[i]).find("td");
                for (var j = 0; j < temp_tr0_tds.length; j++) {
                    if ($(temp_tr0_tds[j]).attr("lang") && $(temp_tr0_tds[j])
                                    .attr("lang") != "suifudan_num") {
                        temp_goodsInput = temp_goodsInput + "<input type='hidden' name='declare.suiFuDans[" + index + "]." + $(temp_tr0_tds[j])
                                        .attr("lang") + "' value=\"" + $(dGoodsTds[j])
                                        .text() + "\" \/>";
                    }
                }
                index++;
            }
            $("#input_declare_suifudans").html("");
            $("#input_declare_suifudans").html(temp_goodsInput);
        }
    }
    $.ajax({
        url: "hgdata-initData",
        success: function (data) {
            var customs = data.data.HGD_2;
            var tradeMode = data.data.HGD_8;
            var levyMode = data.data.HGD_6;
            var lcMode = data.data.HGD_4;
            var dealMode = data.data.HGD_9;
            var addr = data.data.HGD_3;
            var arrivedCountryMode = data.data.HGD_0;
            var goodsCurrencyMode = data.data.HGD_1;
            //已做全局定义
            zhengMian = data.data.HGD_5;
            arrivedCountryMode1 = data.data.HGD_0;
            goodsCurrencyMode1 = data.data.HGD_1;
            if ($("#declareLevymode_1").val() == "undefined" || $("#declareLevymode_1").val() == "") {
// 						alert(0);
// 						autoMethod($("#declareCode_t"));//20140611
                autoZhengMian($("#declareLevymode_1"));
            }
            var goods_levymode = data.data.HGD_5;
            //参数中加了一个#
            initDropDown("#export_show", "#export", customs, 0);
            initDropDown("#trade_show", "#trade", tradeMode, 1);
            initDropDown("#levy_show", "#levy", levyMode, 1);
            initDropDown("#lc_show", "#lc", lcMode, 0);
            initDropDown("#deal_show", "#deal", dealMode, 0);
            initDropDown("#addr_show", "#addr", addr, 0);
            initDropDown("#arrived_country_show", "#arrived_country", arrivedCountryMode, 0);
            initDropDown("#arrived_port_show", "#arrived_port", arrivedCountryMode, 0);
            initDropDown("#goods_destination_show_1", "#goods_destination", arrivedCountryMode, 0);
            initDropDown("#goods_currency_show_1", "#goods_currency", goodsCurrencyMode, 0);
            initDropDown("#goods_levymode_1", "#goods_levymode_val", goods_levymode, 0);
            initDropDown("#freight3_show", "#freight3", goodsCurrencyMode, 0);
            initDropDown("#premium3_show", "#premium3", goodsCurrencyMode, 0);
            initDropDown("#otherfee3_show", "#otherfee3", goodsCurrencyMode, 0);
        }
    });

    /**
     *初始化报关下拉框
     *@param showid 显示用的输入框
     *@param setValueId 保存正式值的输入框
     *@param data 数据源
     */
    function initDropDown(showid, setValueId, data, minlen) {
        var obj = $(showid);
        var objValueInput = $(setValueId);
        var datasource = new Array();
        if (minlen == 0) {

        } else if (minlen == "" || minlen == undefined || minlen == null) {
            minlen = 2;
        }
        $.each(data, function (i, n) {
            datasource.push(n.code + " " + n.name);
        });
        obj.autocomplete({
            minLength: minlen, source: datasource,
            autoFocus: true, delay: 0, select: function (event, ui) {
                var s = ui.item.label;
                objValueInput.val(s.substring(0, s.indexOf(" ")));
                obj.val(s.substring(s.indexOf(" ") + 1, s.length));
                return false;
            }
        });
        if (minlen == 0) {
// 			obj.bind("focus",function(event){obj.autocomplete("search");});
// 			obj.bind("click",function(event){obj.autocomplete("search");});
            dropdownClickEvent(showid);
        }
    }
    // 	$("#businessForm").validationEngine();
    var unitData;
    //成交/法定单位下拉初始化
    $.ajax({
        url: "../base/dropdown-unit",
        success: function (data) {
            var sourcedata = $.map(data.results, function (item) {
                return {label: item[1] + " " + item[0], id: item[1], name: item[0]};
            });
            unitData = sourcedata;
            $("#goods_unit,#goods_legal_unit").autocomplete({
                minLength: 1, autoFocus: true, delay: 0,
                source: sourcedata,
                select: function (event, ui) {
                    var s = ui.item.label;
                    $(this).val(s.substring(s.indexOf(" ") + 1, s.length));
                    return false;
                }
            });
            $("#goods_unit,#goods_legal_unit").bind("focus", function (event) {
                $("#goods_unit,#goods_legal_unit").autocomplete("search");
            });
            $("#goods_unit,#goods_legal_unit").bind("click", function (event) {
                $("#goods_unit,#goods_legal_unit").autocomplete("search");
            });
        }
    });


    var goodsCodeEdit = "";
    function initGoodsCodeEdit() {
        if ($("#goods_code_t").val().length == 8) {
            goodsCodeEdit = $("#goods_code_t").val();
        }
    }

    /**
     *商品编号下拉
     */
    var inputObj = $("#goodsListTB tr:eq(1)");
    var type = "add";
    autoMethod(inputObj, type);
    // 	var code_t_old = "";
    var code_s_old = "";
    var iseEdit = "";
    var codes = new Array();
    $("#goods_code_t").autocomplete({
        minLength: 2,
        autoFocus: true,
        matchContains: true,
        source: function (request, response) {
            var data = {k: $("#goods_code_t").val()};
            $.ajax({
                url: "goodscode-findGoodsCode?tdateaa=" + timeNum(),
                data: data,
                success: function (data) {
                    codes = data.codes;
                    response($.map(data.codes, function (item) {
                        return {
                            label: item.CODE_T + "." + item.CODE_S + " " + item.g_NAME, //商品编号下拉显示内容
                            CODE_S: item.CODE_S, CODE_T: item.CODE_T,
                            GOODS_MODE: item.GOODS_MODE, UNIT_1: item.UNIT_1,
                            UNIT_2: item.ILOW_PRICE, G_NAME: item.g_NAME
                        };
                    }));
                }
            });
        }, select: function (event, ui) {
            var code_t = ui.item.CODE_T;
            var code_s = ui.item.CODE_S;
            var inputObj = $("#goods_code_t");
            $(this).val(ui.item.CODE_T);
            if (code_t_old == code_t && code_s_old == code_s) {
                isEdit = 1;
                loadGoodsCode(ui.item, isEdit, inputObj, type);
            } else {
                isEdit = 2;
                loadGoodsCode(ui.item, isEdit, inputObj, type);
            }
            code_t_old = ui.item.CODE_T;
            code_s_old = ui.item.CODE_S;
            return false;
        }
    });
    //保证选择后，再点击能够加载表格
    $("#goods_code_t").on("focus", function () {
        $(this).autocomplete("search");
    });
    /**
     *经营单位下拉
     */
    var companyQps = new Array();
    $("#company_code")
            .autocomplete({
                autoFocus: true,
                minLength: 2,
                source: function (request, response) {
                    var data = {k: $("#company_code").val()};
                    $
                            .ajax({
                                url: "companyqp-findCompanyByCode?tdateaa=" + timeNum(),
                                data: data,
                                success: function (data) {
                                    companyQps = data.companyQps;
                                    response($
                                            .map(data.companyQps, function (item) {
                                                return {
                                                    label: item.companyCode + " " + item.COMPANY_NAME,
                                                    companyCode: item.companyCode,
                                                    COMPANY_NAME: item.COMPANY_NAME
                                                };
                                            }));
                                }
                            });
                }, select: function (event, ui) {
                    $("#company_code").val(ui.item.companyCode);
                    $("#company_name").val(ui.item.COMPANY_NAME);
                    $("#fahuo_company_co").val(ui.item.companyCode);
                    $("#fahuo_company_name").val(ui.item.COMPANY_NAME);
                    return false;
                }
            });

    /**
     * 发货单位下拉
     */
    var companyQps = new Array();
    $("#fahuo_company_co")
            .autocomplete({
                autoFocus: true,
                minLength: 2,
                source: function (request, response) {
                    var data = {k: $("#fahuo_company_co").val()};
                    $
                            .ajax({
                                url: "companyqp-findCompanyByCode?tdateaa=" + timeNum(),
                                data: data,
                                success: function (data) {
                                    companyQps = data.companyQps;
                                    response($
                                            .map(data.companyQps, function (item) {
                                                return {
                                                    label: item.companyCode + " " + item.COMPANY_NAME,
                                                    companyCode: item.companyCode,
                                                    COMPANY_NAME: item.COMPANY_NAME
                                                };
                                            }));
                                }
                            });
                }, select: function (event, ui) {
                    $("#fahuo_company_co").val(ui.item.companyCode);
                    $("#fahuo_company_name").val(ui.item.COMPANY_NAME);
                    return false;
                }
            });
    //包装方式下拉框
    $("#packet_type").autocomplete({
        autoFocus: true,
        minLength: 0,
        source: function (request, response) {
            var term = request.term;
            var data = goodspackage_type;
            var d = $.map(data, function (item) {
                return {label: item.code + " " + item.name, code: item.code, name: item.name};
            });
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(d, function (value) {
                value = value.label;
                return matcher.test(value);
            }));
        }, select: function (event, ui) {
            $(this).val(ui.item.name);
            return false;
        }
    });

    //运费下拉
    $("#freight1").autocomplete({
        autoFocus: true,
        minLength: 0,
        source: function (request, response) {
            var term = request.term;
            var data = fee1;
            var d = $.map(data, function (item) {
                return {label: item.code + " " + item.name, code: item.code, name: item.name};
            });
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(d, function (value) {
                value = value.label;
                return matcher.test(value);
            }));
        }, select: function (event, ui) {
            $(this).val(ui.item.name);
            return false;
        }
    });

    //保费下拉
    $("#premium1").autocomplete({
        autoFocus: true,
        minLength: 0,
        source: function (request, response) {
            var term = request.term;
            var data = fee1;
            var d = $.map(data, function (item) {
                return {label: item.code + " " + item.name, code: item.code, name: item.name};
            });
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(d, function (value) {
                value = value.label;
                return matcher.test(value);
            }));
        }, select: function (event, ui) {
            $(this).val(ui.item.name);
            return false;
        }
    });

    //杂费下拉
    $("#otherfee1").autocomplete({
        autoFocus: true,
        minLength: 0,
        source: function (request, response) {
            var term = request.term;
            var data = fee1;
            var d = $.map(data, function (item) {
                return {label: item.code + " " + item.name, code: item.code, name: item.name};
            });
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($.grep(d, function (value) {
                value = value.label;
                return matcher.test(value);
            }));
        }, select: function (event, ui) {
            $(this).val(ui.item.name);
            return false;
        }
    });

    //报关类型
    $("#declaretion_type").autocomplete({
        autoFocus: true,
        minLength: 0,
        source: declaretion_type
    });
    dropdownClickEvent("#packet_type");
    dropdownClickEvent("#declaretion_type");


    //miniLength为0时，下拉框输入框被点击或者获得焦点会打开下拉框
    function dropdownClickEvent(id) {
        var obj = $(id);
        obj.bind("focus", function (event) {
            obj.autocomplete("search");
        });
        obj.bind("click", function (event) {
            obj.autocomplete("search");
        });
    }
    /**
     *商品编号  加了个参数inputObj用于辨别订单列表的位置
     */
    function loadGoodsCode(item, isEdit, inputObj, type) {
        var declara_num = $(inputObj).parents("tr").find("td:eq(0)").find("input").val();
        declara_num = parseInt(declara_num) + 1;
        //备案序号
        var recordIdObj = $(inputObj).parent("td").next().next().children("input");
        if ($(recordIdObj).val() == "") {
            //添加了一个参数inputObj
            loadGoodsMode(item.CODE_T, item.CODE_S, item.GOODS_MODE, isEdit, inputObj, type);
        } else {
            //往下个input聚焦  这里是商品名称
            var nextInput = $(recordIdObj).parent("td").next().children("input");
            $(nextInput).focus();
            $(nextInput).select();
        }

        var CODE_T = item.CODE_T;
        var CODE_S = item.CODE_S;
        var G_NAME = item.G_NAME;
        //var UNIT_1 = item.UNIT_1;
        //var UNIT_2 = item.UNIT_2;
        var UNIT_1 = parseUnitDataToChn(item.UNIT_1);
        var UNIT_2 = parseUnitDataToChn(item.UNIT_2);
        $("#goods_code_t").val(CODE_T);
        if (CODE_S != "N") {
// 			$("#goods_code_s").val(CODE_S);
            $("#goods_code_s_" + declara_num).val(CODE_S);
        } else {
// 			$("#goods_code_s").val("00");
            $("#goods_code_s_" + declara_num).val("00");
        }
        //$("#GOODS_NAME").val(G_NAME);
        //if($("#GOODS_UNIT").val() == "") {
        if (goodsCodeEdit != CODE_T) {
            $("#goods_unit_" + declara_num).val(UNIT_1);
            $("#goods_legal_unit_" + declara_num).val(UNIT_1);
            $("#goods_second_unit_" + declara_num).val(UNIT_2);
            //$("#GOODS_DEAL_COUNT").val("");
            //$("#GOODS_LEGAL_COUNT").val("");
// 			$("#goods_second_count_" + declara_num).val("");
            if (UNIT_2 == "" || UNIT_2 == null || UNIT_2 == undefined) {
                $("#goods_second_count_" + declara_num).attr("disabled", true);
                $("#goods_second_unit_" + declara_num).attr("disabled", true);
            } else {
                $("#goods_second_count_" + declara_num).attr("disabled", false);
                $("#goods_second_unit_" + declara_num).attr("disabled", false);
            }
        } else {
            goodsCodeEdit = "";
        }
        initSecondUnit();
        $("#CODE_POSI").attr("class", "0");
    }
    //将成交单位代码解析成中文
    function parseUnitDataToChn(id) {
        while (id.length < 3) {
            id = "0" + id;
        }
        for (var i = 0; i < unitData.length; i++) {
            if (unitData[i].id == id) {
                return unitData[i].name;
            }
        }
    }

    //通过成交方式锁定费用输入框
    $("#deal_show").bind("blur", function (event) {
        var deal = $("#deal").val();
        disabledOneTr("input[name='declare\.freight1']", false);
        disabledOneTr("input[name='declare\.premium1']", false);
        switch (deal) {
            case "1":
                break;
            case "2":
                disabledOneTr("input[name='declare\.premium1']", true);
                break;
            case "3":
                disabledOneTr("input[name='declare\.freight1']", true);
                disabledOneTr("input[name='declare\.premium1']", true);
                break;
            default:
                break;
        }
    });


    /**
     *禁止或者启用某行tr中的所有input,
     @param name tr中的某个 input的selector
     @param disabled 启用或禁止
     */
    function disabledOneTr(inputSelector, disabled) {
        var inputs = $(inputSelector).parent().parent().find("input");
        $.each(inputs, function (i, n) {
            $(n).attr("disabled", disabled);
        });
    }
    //添加了一个参数inputObj用于辨别商品订单的位置
    function loadGoodsMode(code_t, code_s, goods_mode, isEdit, inputObj, type) {
        //mode: 0get,1update
        if (goods_mode == null) {
            return false;
        }
        var re = /:[^;]*;/g;
        var arr = goods_mode.match(re);
        var output = "";
        var length = arr.length;
// 		var gmodeVal = $(inputObj).parent("td").nextAll().eq(4).children("input").val();
        var gmodeVal = $(inputObj).parents("tr").find("td:eq(4)").find("input:eq(1)").val();//获取商品规格值
        gmodeVal = gmodeVal.substring(0, gmodeVal.length);
        gmodeVal = gmodeVal.split("|");
        for (var x = 0; x < length; x++) {
            if (x == 0 && arr[x].indexOf("品名") != -1) {
                continue;
            }
            var label = arr[x];
            label = label.replace(/:/, "");
            label = label.replace(/;/, "");
            var labelVal = gmodeVal[x];
            //如果列表中出现undefined的情况，就把labelVal设为空
            if (labelVal == undefined) {
                labelVal = "";
            }
            var tid = "gmtr_" + x;
            var inputId = "gminput_" + x;
            if (isEdit == "2") {
                output += "<tr id='" + tid + "'><td>" + label + "</td>" + "<td><input type='text' class='goodsModeInput'  /></td></tr>";
            } else if (isEdit == "1") {
                output += "<tr id='" + tid + "'><td>" + label + "</td>" + "<td><input id='" + inputId + "' type='text' class='goodsModeInput' value='" + labelVal + "'  /></td></tr>";
            }

        }
        // 		output += "</tr>";
        output += "<tr><td align='right'><input id='goodsCode' type='button' value='确定' /></td>" + "<td align='left'><input id='goodsCodeCel' value='取消' type='button' onclick='cancel()' /></td></tr>";
        $("#goodsModeInputTB").append(output);
        $("#goodsCode").click(function () {
            setGoodsMode(inputObj);
            var declara_num = $(inputObj).parents("tr").find("td:eq(0)").find("input").val();
            declara_num = parseInt(declara_num) + 1;
            var goods_goods_mode_val = $("#goods_goods_mode_1_" + declara_num).val();
            $("#goods_goods_mode_" + declara_num).val(goods_goods_mode_val);//设置商品规格的值
            if (type == "add") {
                loadGoodsOtherMode(declara_num);
            }
        });
        $("#goodsModeInputTB").show();
        //set data
// 		$("#goods_goods_mode").val().split("|");
        $("#goodsModeInputTB input").first().focus();
        initEnterKey();
    }

    function initEnterKey() {
        var goodsModel = $("#goodsModeInputTB");
        var goodsInput = $("#goodsModeInputTB input");
        if (goodsModel.length != 0) {
            $.each(goodsInput, function (i, n) {
                $(n).bind("keydown", function (event) {
                    if (event.keyCode == 13) {
                        $(goodsInput[i + 1]).focus();
                    }
                });
            });
        }
    }

    function initSecondUnit() {
        var su = $("#goods_second_unit").val();
        if (su == null || su == "") {
            $("#goods_second_count").attr("disabled", true);
            $("#goods_second_count").attr("class", "goodsInput disableInput");
        } else {
            $("#goods_second_count").attr("disabled", false);
            $("#goods_second_count").attr("class", "goodsInput");
        }
    }
    /**
     * 确定
     *参数inputObj是后面添加上去的 用于辨别订单列表的位置
     */
    function setGoodsMode(inputObj) {
        var gmode = "";
        $(".goodsModeInput").each(function (index) {
            gmode += $(this).val() + "|";
        });
        gmode = gmode.substring(0, gmode.length - 1);
        var tgm = gmode.replace(/\|/g, "");

        // 		if($("#RECORD_ID").val() != "" && tgm == "") {
        // 			gmode = "";
        // 		}
        var glength = gmode.replace(/[^\x00-\xff]/g, "xx").length;
        if (glength > 255) {
            alert("商品规格当前长度为" + glength + "个字节，超过标准255个字节，请检查输入");
            return;
        } else {
            var goodsModeObj = $(inputObj).parent("td").next().next().next().next().find("input");

            $(goodsModeObj).val(gmode);//赋值给商品规格
            var declara_num_val = $(inputObj).parents("tr").find("td:eq(0)").find("input").val();
            var declara_num = parseInt(declara_num_val) + 1;
            $("#goods_goods_mode_1_" + declara_num).val(gmode);//赋值给id为goods_goods_mode_1的商品规格
            var inputObj1 = $(inputObj).parent("td").next("td").next("td").next("td").find("input");
            $(inputObj1).focus();
            $(inputObj1).select();
// 			$("#goods_goods_mode").val(gmode);
// 			$("#goods_count").focus();
// 			$("#goods_count").select();
        }
        $("#goodsModeInputTB").find("tr").remove();
        $("#goodsModeInputTB").hide();
// 		$($(".goodsModeInput")[0]).focus();
// 		$($(".goodsModeInput")[0]).select();
    }

    /**
     * 取消
     */
    function cancel() {
        // 		$("#goodsModeInputTB").hide();
        $("#goodsModeInputTB").find("tr").remove();
        $("#goods_code_t").val("");
        $("#goods_code_s").val("");
        $("#goods_unit").val("");
        $("#goods_legal_unit").val("");
        $("#goods_second_unit").val("");
    }

    /**
     * 版本号等信息的确认
     */
    function otherConfirm(declara_num) {
        var goods_count_other = $("#goods_count_other").val();//成交数量
        var goods_unit_other = $("#goods_unit_other").val();//成交单位
        var goods_legal_count_other = $("#goods_legal_count_other").val();//法定数量
        var goods_legal_unit_other = $("#goods_legal_unit_other").val();//法定单位
        var goods_second_count_other = $("#goods_second_count_other").val();//第二数量
        var goods_second_unit_other = $("#goods_second_unit_other").val();//第二单位
        var goods_version_no_other = $("#goods_version_no_other").val();//版本号
        $("#goods_count_" + declara_num).val(goods_count_other);
        $("#goods_count_1_" + declara_num).val(goods_count_other);
        $("#goods_unit_" + declara_num).val(goods_unit_other);
        $("#goods_unit_1_" + declara_num).val(goods_unit_other);
        $("#goods_legal_count_" + declara_num).val(goods_legal_count_other);
        $("#goods_legal_count_1_" + declara_num).val(goods_legal_count_other);
        $("#goods_legal_unit_" + declara_num).val(goods_legal_unit_other);
        $("#goods_legal_unit_1_" + declara_num).val(goods_legal_unit_other);
        $("#goods_second_count_" + declara_num).val(goods_second_count_other);
        $("#goods_second_count_1_" + declara_num).val(goods_second_count_other);
        $("#goods_second_unit_" + declara_num).val(goods_second_unit_other);
        $("#goods_second_unit_1_" + declara_num).val(goods_second_unit_other);
        $("#goods_version_no_" + declara_num).val(goods_version_no_other);

        $("#goods_destination_show_" + declara_num).focus();
        $("#goods_destination_show_" + declara_num).select();

        $("#goodsModeOtherInputTB").find("tr").remove();
        $("#goodsModeOtherInputTB").hide();
    }

    /**
     * 版本号等信息的取消
     */
    function otherCancel() {
        $("#goodsModeOtherInputTB").find("tr").remove();
        $("#goodsModeOtherInputTB").hide();
    }

    /**
     * 版本号等信息的弹出框
     */
    function loadGoodsOtherMode(declara_num) {
        var unitData;
        //成交单位下拉初始化
        $.ajax({
            url: "../base/dropdown-unit",
            success: function (data) {
                var sourcedata = $.map(data.results, function (item) {
                    return {label: item[1] + " " + item[0], id: item[1], name: item[0]};
                });
                unitData = sourcedata;
                $("#goods_unit_other").autocomplete({
                    minLength: 1, autoFocus: true, delay: 0,
                    source: sourcedata,
                    select: function (event, ui) {
                        var s = ui.item.label;
                        $(this).val(s.substring(s.indexOf(" ") + 1, s.length));
                        return false;
                    }
                });
                $("#goods_unit_other").bind("focus", function (event) {
                    $("#goods_unit_other").autocomplete("search");
                });
                $("#goods_unit_other").bind("click", function (event) {
                    $("#goods_unit_other").autocomplete("search");
                });
            }
        });

        //法定单位下拉初始化
        $.ajax({
            url: "../base/dropdown-unit",
            success: function (data) {
                var sourcedata = $.map(data.results, function (item) {
                    return {label: item[1] + " " + item[0], id: item[1], name: item[0]};
                });
                unitData = sourcedata;
                $("#goods_legal_unit_other").autocomplete({
                    minLength: 1, autoFocus: true, delay: 0,
                    source: sourcedata,
                    select: function (event, ui) {
                        var s = ui.item.label;
                        $(this).val(s.substring(s.indexOf(" ") + 1, s.length));
                        return false;
                    }
                });
                $("#goods_legal_unit_other").bind("focus", function (event) {
                    $("#goods_legal_unit_other").autocomplete("search");
                });
                $("#goods_legal_unit_other").bind("click", function (event) {
                    $("#goods_legal_unit_other").autocomplete("search");
                });
            }
        });
// 		declara_num = declara_num + 1;
        var output = "";
        var goods_code_s = $("#goods_code_s_" + declara_num).val();
        var goods_version_no = $("#goods_version_no_" + declara_num).val();
        var goods_count = $("#goods_count_" + declara_num).val();
        var goods_unit = $("#goods_unit_" + declara_num).val();
        var goods_legal_count = $("#goods_legal_count_" + declara_num).val();
        var goods_legal_unit = $("#goods_legal_unit_" + declara_num).val();
        var goods_second_count = $("#goods_second_count_" + declara_num).val();
        var goods_second_unit = $("#goods_second_unit_" + declara_num).val();

// 		output += "<tr id='goods_code_s_tr'><td  class='labelTD'>" + "附加编号" + "</td>" + "<td><input id='goods_code_s_other' type='text' value='"+goods_code_s+"' disabled='disabled'/></td></tr>";
        output += "<tr id='goods_count_tr'><td class='labelTD'>"
                + "成交数量"
                + "</td>"
                + "<td><input id='goods_count_other' type='text' value='" + goods_count + "'/></td><td class='labelTD'>成交单位</td><td><input id='goods_unit_other' type='text' value='" + goods_unit + "'/></td></tr>";
// 		output += "<tr id='goods_unit_tr'><td class='labelTD'>" + "成交单位" + "</td>" + "<td><input id='goods_unit_other' type='text' value='"+goods_unit+"'/></td></tr>";
        output += "<tr id='goods_second_count_tr'><td class='labelTD'>"
                + "法定数量"
                + "</td>"
                + "<td><input id='goods_legal_count_other' type='text' value='" + goods_legal_count + "'/></td><td class='labelTD'>法定单位</td><td><input id='goods_legal_unit_other' type='text' value='" + goods_legal_unit + "'/></td></tr>";
        output += "<tr id='goods_second_count_tr'><td class='labelTD'>"
                + "第二数量"
                + "</td>"
                + "<td><input id='goods_second_count_other' type='text' value='" + goods_second_count + "'/></td><td class='labelTD'>第二单位</td><td><input id='goods_second_unit_other' type='text' value='" + goods_second_unit + "' disabled='disabled'/></td></tr>";
// 		output += "<tr id='goods_second_unit_tr'><td class='labelTD'>"+ "第二单位"+ "</td>" + "<td><input id='goods_second_unit_other' type='text' value='"+goods_second_unit+"' disabled='disabled'/></td></tr>";
        output += "<tr id='goods_version_no_tr'><td class='labelTD'>"
                + "版本号"
                + "</td>"
// 				+ "<td><input id='goods_version_no_other' type='text' value='"+goods_version_no+"'/></td><td  class='labelTD'>附加编号</td><td><input id='goods_code_s_other' type='text' value='"+goods_code_s+"' disabled='disabled'/></td></tr>";
                + "<td><input id='goods_version_no_other' type='text' value='" + goods_version_no + "'/></td><td  class='labelTD'></td><td  class='labelTD'></td></tr>";
        output += "<tr><td></td><td align='right'><input id='loadGoodsOtherModeConfirm' type='button' onclick='otherConfirm(" + declara_num + ")' value='确定' /></td>"
                + "<td align='left'><input id='goodsCodeCel' value='取消' type='button' onclick='otherCancel()' /></td><td></td></tr>";
        $("#goodsModeOtherInputTB").append(output);
        $("#goodsModeOtherInputTB").show();

        // 		$("#goodsModeOtherInputTB input").first().focus();
        // 		$("#goodsModeOtherInputTB input").first().select();
        $("#goods_count_other").focus();
        $("#goods_count_other").select();
        initOtherEnterKey();

    }

    function initOtherEnterKey() {
        var goodsModel = $("#goodsModeOtherInputTB");
        var goodsInput = $("#goodsModeOtherInputTB input");
        if (goodsModel.length != 0) {
            $.each(goodsInput, function (i, n) {
                $(n).bind("keydown", function (event) {
                    if (event.keyCode == 13) {
                        var inputId = $(this).attr("id");
                        if (inputId == "goods_second_count_other") {
                            $(goodsInput[i + 2]).focus();
                        }
                        $(goodsInput[i + 1]).focus();
                    }
                });
            });
        }
    }

    $(function () {
        //输入框切换 按回车键
        $("input")
                .each(
                        function (index) {
                            $(this)
                                    .bind(
                                            "keydown",
                                            function (event) {
                                                var inputId = $(this)
                                                        .attr("id");
                                                var inputName = $(this).attr(
                                                        "name");
                                                if (event.keyCode == 13) {
                                                    var posi = index;
                                                    // 									changeInputTo(posi + 1);
                                                    if (inputName == "declare.net_weight") {
                                                        var net_weight_input = $("input[name=declare\\.net_weight]");
                                                        var gross_weight_input = $("input[name=declare\\.gross_weight]");
                                                        var net_weight = new Number(
                                                                net_weight_input
                                                                        .val());
                                                        var gross_weight = new Number(
                                                                gross_weight_input
                                                                        .val());
                                                        if (net_weight >= gross_weight) {
                                                            net_weight_input
                                                                    .val("");
                                                            net_weight_input
                                                                    .focus();
                                                            alert("净重不能大于毛重");
                                                        }
                                                    } else if (inputId == "goods_code_t") {
                                                        if ($("#goodsModeInputTB tr").length == 0) {
                                                            // 											changeInputTo(posi+3);
                                                        }
                                                    } else if (inputId == "goods_count") {
                                                        if ($("#goods_unit")
                                                                        .val() == $(
                                                                        "#goods_legal_unit")
                                                                        .val()) {
                                                            $(
                                                                    "#goods_legal_count")
                                                                    .val(
                                                                            $(
                                                                                    "#goods_count")
                                                                                    .val());
                                                        }
                                                    } else if (inputId == "goods_total_price") {
                                                        var count = new Number(
                                                                $(
                                                                        "#goods_count")
                                                                        .val());
                                                        var price = new Number(
                                                                $(
                                                                        "#goods_total_price")
                                                                        .val());
                                                        var unit_price = Math
                                                                        .round((price / count) * 10000) / 10000;
                                                        $("#goods_unit_price")
                                                                .val(unit_price);
                                                        changeInputTo(posi - 2);
                                                    } else if (inputId == "goods_unit") {
                                                        if ($(
                                                                        "#goods_record_id")
                                                                        .attr(
                                                                                "disabled")) {
                                                            changeInputTo(posi + 5);
                                                        }
                                                    } else if (inputId == "arrived_country_show") {
                                                        $("#arrived_port_show")
                                                                .val(
                                                                        $(
                                                                                "#arrived_country_show")
                                                                                .val());
                                                        $("#arrived_port")
                                                                .val(
                                                                        $(
                                                                                "#arrived_country")
                                                                                .val());
                                                        changeInputTo(posi + 2);
                                                    } else if (inputId == "goods_destination_show"
                                                            || inputId == "goods_currency_show") {
                                                        changeInputTo(posi + 1);
                                                    } else if (inputId == "declaration_sup_id"
                                                            || inputId == "export_show"
                                                            || inputId == "trade_show"
                                                            || inputId == "levy_show"
                                                            || inputId == "lc_show"
                                                            || inputId == "arrived_country_show"
                                                            || inputId == "arrived_port_show"
                                                            || inputId == "addr_show"
                                                            || inputId == "deal_show"
                                                            || inputId == "goods_levymode"
                                                            || inputId == "freight3_show"
                                                            || inputId == "premium3_show"
                                                            || inputId == "otherfee3_show") {
                                                        changeInputTo(posi + 2);
                                                    } else if (inputId == "goods_processing_fee"
                                                            || inputId == "goods_suifudan_no") {
                                                        changeInputTo(posi + 3);
                                                    } else if (inputId == "record_id") {
                                                        if ($(this).val != "") {
                                                            //$("#goods_record_id")
                                                            //		.attr("disabled", false);
                                                            //initBeiAnMode();
                                                            //$("#goods_count").focus();
                                                            var record_id = $(
                                                                    "#record_id")
                                                                    .val();
                                                            if (record_id
                                                                            .charAt(0) == "C") {
                                                                $("#trade_show")
                                                                        .val(
                                                                                "进料对口");
                                                                $("#levy_show")
                                                                        .val(
                                                                                "进料加工");
                                                                $(
                                                                        "td[lang='processing_fee']")
                                                                        .attr(
                                                                                "style",
                                                                                "width : 60px;");
                                                            } else if (record_id
                                                                            .charAt(0) == "B") {
                                                                $("#trade_show")
                                                                        .val(
                                                                                "来料加工");
                                                                $("#levy_show")
                                                                        .val(
                                                                                "来料加工");
                                                                $(
                                                                        "td[lang='processing_fee']")
                                                                        .attr(
                                                                                "style",
                                                                                "width : 60px;");
                                                            } else {
                                                                if (record_id == null || record_id == "") {
                                                                    $("td[lang='processing_fee']").attr("style", "width : 50px; display : none;");
                                                                }
                                                            }
                                                        }
                                                    } else if (inputId == "goods_name_1") {
                                                        var goods_name_1 = $(
                                                                "#goods_name_1")
                                                                .val();
                                                        $("#goods_name").val(
                                                                goods_name_1);
                                                    }

                                                }
                                            });
                        });
        //页面默认值
        setDefaultValue("#trade_show", "一般贸易");
        setDefaultValue("#trade", "0110");
        setDefaultValue("#levy_show", "一般征税");
        setDefaultValue("#levy", "101");
        setDefaultValue("#deal_show", "FOB");
        setDefaultValue("#deal", "3");
        setDefaultValue("#remark", "佛山新港");
        setDefaultValue("#transport_mode", "水路运输");
        setDefaultValue("#export_show", "佛山新港");
        setDefaultValue("#export", "5189");
        disabledOneTr("input[name='declare\.freight1']", true);
        disabledOneTr("input[name='declare\.premium1']", true);
        setDefaultValue("#declaretion_type", "通关无纸化");

        //初始化页面时当备案号不为空时加载工缴费
        var record_id_val = $("#record_id").val();
        if (record_id_val == null || record_id_val == "") {
            $("td[lang='processing_fee']").attr("style", "width : 60px; display : none;");
        } else {
            $("td[lang='processing_fee']").attr("style", "width : 60px;");
        }
    });

    function setDefaultValue(inputSelect, value) {
        if ($(inputSelect).val() == "" || $(inputSelect).val() == undefined
                || $(inputSelect).val() == null) {
            $(inputSelect).val(value);
        }
    }

    /**
     * 备案模型
     */
    function initBeiAnMode() {
        var RECORD_ID = $("#record_id").val();
        if (RECORD_ID.charAt(0) == "C") {
            $("#trade_show").val("进料对口");
            $("#levy_show").val("进料加工");
            $("#goods_levymode").val("全免");
            // 			propertiesJson.GOODS_LEVYMODE = "全免";
        } else if (RECORD_ID.charAt(0) == "B") {
            $("#trade_show").val("来料加工");
            $("#levy_show").val("来料加工");
            $("#goods_levymode").val("全免");
            // 			propertiesJson.GOODS_LEVYMODE = "全免";
        }
        // 		initBeiAn();
    }

    /**
     * 输入框移动方法
     */
    function changeInputTo(posi) {
        $("input").each(function (index) {
            if (index == posi) {
                if ($(this).attr("disabled")) {
                    posi++;
                    changeInputTo(posi);
                } else {
                    $(this).focus();
                    $(this).select();
                }
            }
        });
    }

    /**
     * 检查备案号的长度
     */
    function checkRECORD_ID() {
        var test = $("#record_id").val();
        if (test.length > 0 && test.length != 12) {
            alert("备案号长度不正确，标准长度为12，请检查输入");
            // 			$("#record_id").focus();
            $("#record_id").select();
        }
        if (test.length == 0) {
            $("#goods_record_id").attr("disabled", true);
        } else if (test.length == 12) {
            $("#goods_record_id").attr("disabled", false);
        }
        // 		else if(test.length == 12){
        // 			$("#ITEM_QTY_div").show();
        // 		}
    }
    // 	$(function(){
    // 		var length = $("#goodsListTB tr").length-1;
    // 		var span = $("#goodsListTB tr:eq("+length+") td:eq(11) span:eq(1)");
    // 		span.css("display","inline");
    // // 		autoMethod($("#declareCode_t"));
    // // 		autoZhengMian($("#declareLevymode"));
    // 	});
</script>
